自定义UITableVIewCell初始化未调用 [英] Custom UITableVIewCell initialization not called

查看:303
本文介绍了自定义UITableVIewCell初始化未调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have custom UiTablleviewCell with some images and labels, and I would like to have rotated label in tableview cell...so I would like to edit initWithStyle method, but it seems like it's never called.

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

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

but in my log, I cant see this message. In tableview I have standard cellForRow method

- (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,我可以想一些解决方法,但我想让它干净。
谢谢。

so I'm wondering how does tableview initialize tableviewcells, I can think about some workarounds but I would like to have it clean. Thank you.

推荐答案

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

If the cells come from a storyboard or nib file, then initWithStyle:reuseIdentifier is not called, initWithCoder: is called instead.

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

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

如果您需要在自定义初始化期间访问IBOutlet,则无效。

这篇关于自定义UITableVIewCell初始化未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆