Re: [問題] collection view cell 初始化
如果你的view是從xib或storyboard讀進來的話
它會跑initWithCoder
initWithCoder: - Implement this method if you load your view from an Interface Builder nib file and your view requires custom initialization.
UIView Class Reference 搜尋Methods to Override就會看到了
https://developer.apple.com/library/ios/documentation/uikit/reference/uiview_class/UIView/UIView.html
EX:
- (id)initWithCoder:(NSCoder *)aDecoder
{
if(self = [super initWithCoder:aDecoder])
{
self.xxx = oooo;
}
return self;
}
※ 引述《issuemylove (skill)》之銘言:
: 想請問各位大大
: 因為 cell 會重複使用
: 但是有些東西每個 cell 都是一樣的 (只須設定一次)
: 例如: cell 的背景顏色、邊框圓角等
: 我想要只設定一次 而不是傻傻地在 cellForItemAtIndexPath 裡每次都設定
: 即是在自訂的cell中 實作 -(id)initWithFrame
: 請問有甚麼好方法嗎?
: 我目前是 viewDidLoad 使用
: [collectionView registerNib: forCellWithReuseIdentifier: ]
: 然後在 cellForItemAtIndexPath 裡面做設定
: 但這樣並不會觸發自訂cell的 initWithFrame
: 有試過這篇的方法http://stackoverflow.com/questions/17406186/ 使用 registerClass
: 的確是會觸發 initWithFrame 但是就我的cell 卻離奇的消失不顯示 只是透明
: 請問我該怎麼辦才好QQ
: 還是說有甚麼其他方法呢?
: 謝謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.36.63.52
※ 編輯: whitefur 來自: 114.36.63.52 (09/26 17:38)
→
09/27 10:52, , 1F
09/27 10:52, 1F
→
09/27 10:52, , 2F
09/27 10:52, 2F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 3 之 3 篇):
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章