UITableView
2017-06-05 本文已影响0人
John易筋
Question: Custom UITableViewCell initialization not called
** reference methods: **
init
initWithFrame
initWithStyle:reuseIdentifier:
initWithCoder:
awakeFromNib
-
init
not be called -
initWithFrame
not be called - If the cells come from a storyboard or nib file, call
initWithCoder:
firstly and callawakeFromNib
later. Be carefulinitWithCoder:
is availability (9.0 and later), tvOS (9.0 and later). - If the cells come from coder
registerClass:forCellReuseIdentifier:
, callinitWithStyle:reuseIdentifier:
instead.
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// self.contentView.bounds = [UIScreen mainScreen].bounds;
// ...
}
return self;
The answer can be found in the method description - (__kindof UITableViewCell *)dequeueReusableCellWithIdentifier:(NSString *)identifier forIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(6_0);
Important
You must register a class or nib file using the registerNib:forCellReuseIdentifier: or registerClass:forCellReuseIdentifier: method before calling this method.
If you registered a class for the specified identifier and a new cell must be created, this method initializes the cell by calling its initWithStyle:reuseIdentifier: method. For nib-based cells, this method loads the cell object from the provided nib file. If an existing cell was available for reuse, this method calls the cell’s prepareForReuse method instead.
优化UITableViewCell高度计算的那些事
UITableViewCell 利用 AutoLayout 自动高度计算和 UITableView 滑动优化的一个总结。
sunnyxx在维护一个开源的扩展,UITableView+FDTemplateLayoutCell,让高度计算这个事情变的前所未有的简单,也受到了很多星星的支持,github链接请戳我 https://github.com/forkingdog/UITableView-FDTemplateLayoutCell
优化UITableViewCell高度计算的那些事 总结你可以读到:
- UITableView高度计算和估算的机制
- 不同iOS系统在高度计算上的差异
- iOS8 self-sizing cell
- UITableView+FDTemplateLayoutCell如何用一句话解决高度问题
- UITableView+FDTemplateLayoutCell中对RunLoop的使用技巧