ios – 未调用自定义UITableVIewCell初始化

栏目: IOS · 发布时间: 7年前

内容简介:翻译自:https://stackoverflow.com/questions/20313611/custom-uitableviewcell-initialization-not-called

我有一些图像和标签的自定义UiTablleviewCell,我想在tableview单元格中旋转标签…所以我想编辑initWithStyle方法,但似乎从未调用过.

- (id)initWithStyle:(UITableViewCellStyle)stylereuseIdentifier:(NSString*)reuseIdentifier{
NSLog(@"creating cell");
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self)
{
}
return self;}

但在我的日志中,我看不到这条消息.在tableview中我有标准的cellForRow方法

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{    
    static NSString *simpleTableIdentifier = @"messagesCell";
    TBCellMessagesCell *cell = (TBCellMessagesCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    // smt stuff

    return cell;
}

所以我想知道tableview如何初始化tableviewcells,我可以考虑一些解决方法,但我想让它干净.

谢谢.

如果单元格来自故事板或nib文件,则不调用initWithStyle:reuseIdentifier,而是调用initWithCoder :.

这是覆盖的initWithCoder的典型实现::

-(id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
       // Do your custom initialization here
    }
    return self;
}

如果您需要在自定义初始化期间访问IBOutlet,则无法工作.

翻译自:https://stackoverflow.com/questions/20313611/custom-uitableviewcell-initialization-not-called


以上所述就是小编给大家介绍的《ios – 未调用自定义UITableVIewCell初始化》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

An Introduction to Probability Theory and Its Applications

An Introduction to Probability Theory and Its Applications

William Feller / Wiley / 1991-1-1 / USD 120.00

Major changes in this edition include the substitution of probabilistic arguments for combinatorial artifices, and the addition of new sections on branching processes, Markov chains, and the De Moivre......一起来看看 《An Introduction to Probability Theory and Its Applications》 这本书的介绍吧!

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换