【问题标题】:Error in UITableViewUITableView 中的错误
【发布时间】:2012-02-03 01:46:18
【问题描述】:

我正在创建一个 UITableView,代码中的每一件事都很顺利,并且构建成功了,但是当我在模拟器中运行时。它显示错误为:

线程 1:程序收到信号:“EXC_BAD_ACCESS”。

在下面找到我的代码供您参考:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell =[tableView dequeueReusableCellWithIdentifier:@"Mycell"];
    if(cell == nil){
        cell =[[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"MYcell"]autorelease];
    }
    cell.textLabel.text=[NSString stringWithFormat:@"cell %@",(unsigned long)indexPath.row+1];

    return  cell;
}

错误在这一行:

cell.textLabel.text=[NSString stringWithFormat:@"cell %@",(unsigned long)indexPath.row+1];

请发表您的建议

【问题讨论】:

    标签: iphone objective-c ios ipad uitableview


    【解决方案1】:

    您使用了错误的格式说明符。 %@ 表示对象,使用 %d 表示整数:

    cell.textLabel.text=[NSString stringWithFormat:@"cell %d",(unsigned long)indexPath.row+1];
    

    【讨论】:

      【解决方案2】:

      使用

      cell.textLabel.text=[NSString stringWithFormat:@"cell %d",(unsigned long)indexPath.row+1];
      

      而不是

      cell.textLabel.text=[NSString stringWithFormat:@"cell %@",(unsigned long)indexPath.row+1];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-03-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-14
        • 1970-01-01
        • 2018-02-23
        相关资源
        最近更新 更多