自定义UITableViewCell委托其子视图?

时间:2012-12-19 05:22:56

标签: ios xcode uitableview

我有custom celltextfield作为子视图。将单元格设置为textfield的委托是否合法?

我想将单元格设置为委托,因为它是父视图,但是当我这样做时,应用程序崩溃了。我想这是因为table view dequeue cells,也许这就是委托引用在两者之间丢失的原因。 所以,我尝试在cellForRowAtIndexPath中设置委托,以确保每次都设置新的委托,但它仍然不起作用。

我是否真的必须提升级别并让tableview controller成为单元格子视图的代理?或者我错过了其他什么?

崩溃报告输出:

>libobjc.A.dylib`objc_msgSend:
>
0x32ed4f78:  ldr    r3, [r4, #8]
>

initWithStyle我有

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier type: (NSString *)cellType
{

self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
    // Initialization code
    NSArray *nibArray = [[NSBundle mainBundle] loadNibNamed:@"Custom Cell" owner:self options:nil];
    self = [nibArray lastObject];

    self.cellType = [NSString stringWithString:cellType];
    self.contentText.autoresizingMask = UIViewAutoresizingNone;
    self.detailLabel.autoresizingMask = UIViewAutoresizingNone;
    self.contentText.delegate = self;
}
return self;
}

2 个答案:

答案 0 :(得分:0)

将自定义单元格作为单元格中文本字段的委托不是问题。表视图将在需要时重用某些单元格,但不会影响任何内容。我猜你错过了其他的东西。如果您发布崩溃时遇到的错误以及代码的相应部分,也许我可以提供帮助。

答案 1 :(得分:0)

请勿在{{1​​}}

中设置delegate

cellForRowAtIndexPath.子类中,在UITableViewCell方法中添加UITextField,然后将initWithStyle设置为delegate

相关问题