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

标签 iphone objective-c ios uitableview uilabel

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

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/

相关文章:

ios - 如何将swift代码转换为 objective-c

objective-c - 在 iPhone 上实现自定义 UITextView 界面的技巧?

iphone - MFMailComposeViewController 模型不显示

iphone - 获取特定地理位置的时间

ios - quicklook 不显示图像但有正确的数据

c# - 获取联系人容器 Xamarin.iOS 时出现问题

ios - Xamarin:FFImageLoading 不显示在 iOS 上使用内部 ListView

ios - Swift 内存布局

iphone - 代码 : Horizontal Scrolling in a TableViewCell

iphone - 查找最小/最大纬度和经度