我对IOS开发相当陌生,所以我很抱歉如果这是一个无知的问题。打开ARC后UITableViewCell.contentView错误
重构我的代码使用ARC之后,我开始变得时执行以下线,被抛出SIGABRT错误:
UILabel *label = (UILabel *)[cell.contentView viewWithTag:labelTag];
控制台输出包括以下内容:
“ NSInvalidArgumentException”的,原因是: ' - [__ NSArrayM内容查看]:无法识别的选择发送到实例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的子类。
@implementation TextFieldCellController
@synthesize label;
@synthesize textField;
- (id)init {
self = (TextFieldCellController *)[[NSBundle mainBundle] loadNibNamed:@"TextFieldCell" owner:self options:nil];
return self;
}
消息告诉你'cell'指向'__NSArrayM'类的对象,它是'NSArray'接口的私有实现。所以让我们看看' - [TextFieldCellController init]'方法。 – 2012-03-03 05:06:11
TextFieldCellController这是什么??,而且你没有正确地创建单元格。请看这个链接http://stackoverflow.com/questions/9494281/how-is-the-code-for-uploading-the-parsed-data-到了-的tableview/9494402#9494402。 – Kamarshad 2012-03-03 05:07:27
我已经更新了最初的问题来描述子类。 – Leedrick 2012-03-03 07:29:27