作者whitefur (白毛)
看板MacDev
标题Re: [问题] collection view cell 初始化
时间Thu Sep 26 17:26:23 2013
如果你的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)
1F:→ issuemylove:谢谢! 成功了XD 简单好用 也不用塞到 cellForItemXX里 09/27 10:52
2F:→ issuemylove:小弟还是个新手 问新手问题还请多多海涵QQ 09/27 10:52