UITableView

2017-06-05  本文已影响0人  John易筋

Question: Custom UITableViewCell initialization not called

** reference methods: **

  1. init not be called
  2. initWithFrame not be called
  3. If the cells come from a storyboard or nib file, call initWithCoder: firstly and call awakeFromNib later. Be careful initWithCoder: is availability (9.0 and later), tvOS (9.0 and later).
  4. If the cells come from coder registerClass:forCellReuseIdentifier:, call initWithStyle: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高度计算的那些事 总结你可以读到:

上一篇下一篇

猜你喜欢

热点阅读