当我想要设置属于表格单元的标签文本时,我的应用程序崩溃。我的代码段如下:
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'
任何建议对此表示极大的赞赏!
震
最佳答案
您设置为splitMethodLabel的标记值似乎可能导致了问题。Just change the tag value to something else and check if it crashes still.
关于iphone - 将文本设置为自定义表格单元格标签时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5740809/