【发布时间】:2011-04-21 07:15:42
【问题描述】:
当我想设置属于表格单元格的标签文本时,我的应用程序崩溃了。我的代码sn-p如下:
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";
问题似乎出在我设置文本的时候。 下面的堆栈跟踪:
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'
非常感谢您对此提出任何建议!
镇
【问题讨论】:
-
发布堆栈跟踪总是一个好主意:)
-
@Zhen: 把tag的值改成别的,看看是不是还是崩溃。
-
@Simon,是的,你是对的。我将 0 分配给导致应用程序崩溃的标签值。我将值更改为 1,它现在工作正常。非常感谢您的帮助!
-
@Simon +1 供您发表评论,您应该将其作为答案发布,以便其他人在将来找到它。
标签: iphone objective-c ios uitableview uilabel