Objective c 启用ARC后UITableViewCell.contentView错误

Objective c 启用ARC后UITableViewCell.contentView错误,objective-c,ios,Objective C,Ios,我对IOS开发相当陌生,所以如果这是一个无知的问题,我道歉 在重构代码以使用ARC之后,我开始得到一个SIGABRT错误,该错误在执行以下行时抛出: UILabel *label = (UILabel *)[cell.contentView viewWithTag:labelTag]; 控制台输出包括以下内容: 'NSInvalidArgumentException',原因:'-[\uu NSArrayM contentView]:无法识别的选择器发送到实例0x1acba0' 该行的上下文是:

我对IOS开发相当陌生,所以如果这是一个无知的问题,我道歉

在重构代码以使用ARC之后,我开始得到一个SIGABRT错误,该错误在执行以下行时抛出:

UILabel *label = (UILabel *)[cell.contentView viewWithTag:labelTag];
控制台输出包括以下内容:

'NSInvalidArgumentException',原因:'-[\uu NSArrayM contentView]:无法识别的选择器发送到实例0x1acba0'

该行的上下文是:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    const NSInteger labelTag = 1;
    const NSInteger textFieldTag = 2;

    UITableViewCell *cell = nil;

    if([indexPath section] == 0) {
        if([indexPath row] == 0) {
            //this is the username row. Set the label accordingly.

            cell = [[TextFieldCellController alloc] init];

            UILabel *label = (UILabel *)[cell.contentView viewWithTag:labelTag];
            label.text = @"Username";
        }
        else if([indexPath row] == 1) {
            //this is the row that contains the password input. Set the label and
            //change the textfield to use a password input style.

            cell = [[TextFieldCellController alloc] init];

            UILabel *label = (UILabel *)[cell.contentView viewWithTag:labelTag];
            label.text = @"Password";

            UITextField *text = (UITextField *)[cell.contentView viewWithTag:textFieldTag];
            text.secureTextEntry = YES;


        }
    }
    return cell;
}
我在控制台窗口中玩游戏,当我在那一行输入“print cell.contentView”后,我得到了“没有名为contentView的成员”。我不确定这是否有用

提前感谢您的帮助

编辑:

抱歉,TextFieldCellController是UITableViewCell的子类,它加载包含标签和文本字段的nib

@implementation TextFieldCellController

@synthesize label;
@synthesize textField;

- (id)init {
    self = (TextFieldCellController *)[[NSBundle mainBundle] loadNibNamed:@"TextFieldCell" owner:self options:nil];
    return self;
}

这不是实现
cellforrowatinexpath
的方法。为什么不调用
dequeueReusableCellWithIdentifier:

而且(可能更重要的是)您不能像那样调用
alloc init
来创建表视图单元格。指定的初始值设定项是
initWithStyle:reuseIdentifier:
;我相信你一定会这么说


最后,我非常怀疑这个TextFieldCellController。如果它是UITableViewCell子类,那么像这样初始化它不会导致它有任何标记为1或2的子视图。如果它不是UITableViewCell子类,那么它到底是什么?我希望您没有使用UIViewController从nib加载单元格;那就大错特错了。

消息告诉您,
cell
指向类
\uu NSArray
的对象,它是
NSArray
接口的私有实现。因此,请向我们展示
-[TextFieldCellController init]
方法。TextFieldCellController这是什么…?,您没有正确创建单元格。请参阅此链接。我已更新了初始问题以描述子类。我认为dequeueReusableCellWithIdentifier是可选的?我花了一段时间试图弄清楚如何拥有一个可重用的定制单元。在我启用ARC之前,它一直在工作。你能告诉我一个更好的方法吗?我已经更新了最初的问题。