将文本设置为自定义表格单元格标签时发生崩溃

Zhe*_*hen 1 iphone objective-c uitableview uilabel ios

当我想设置属于表格单元格的标签文本时,我的应用程序崩溃了.我的代码片段如下:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];

if (cell == nil) 
{
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:simpleTableIdentifier];
    [cell autorelease];

    CGRect splitMethodLabelRect = CGRectMake(160, 6, 50, 30); 
    UILabel *splitMethodLabel = [[UILabel alloc] initWithFrame:splitMethodLabelRect]; 
    splitMethodLabel.textAlignment = UITextAlignmentLeft; 
    splitMethodLabel.font = [UIFont systemFontOfSize:13]; 
    splitMethodLabel.tag = kSplitMethodTag;
    [cell.contentView addSubview: splitMethodLabel]; 
    [splitMethodLabel release];

}

UILabel *splitMethodName = (UILabel *)[cell.contentView viewWithTag:kSplitMethodTag]; 

//app crashes at this point
splitMethodName.text = @"Test"; 
Run Code Online (Sandbox Code Playgroud)

这个问题似乎就在我设置文本时.Stacktrace如下:

2011-04-21 15:11:10.820 BillSplitter[3021:707] -[UITableViewCellContentView setText:]: unrecognized selector sent to instance 0x18a680
2011-04-21 15:11:10.829 BillSplitter[3021:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableViewCellContentView setText:]: unrecognized selector sent to instance 0x18a680'
Run Code Online (Sandbox Code Playgroud)

任何建议都非常感谢!

Emp*_*ack 6

您设置为splitMethodLabel标记值似乎可能导致问题.
Just change the tag value to something else and check if it crashes still.