2012-09-27 85 views
0

我在UITableViewController场景中创建了5个静态单元格。一切工作正常,但我无法设置选定的特定单元格!如果它是原型单元,那么它很简单,但我怎么能设置静态单元格选择?以下代码引发了BAD内存访问异常!我已根据discussion on apple thread完成此操作,但不知道有什么问题!有人可以帮忙吗?iOS 6.0 Storyboard:设置静态单元格

- (void)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [super tableView:tableView cellForRowAtIndexPath:indexPath]; 

    if(indexPath.section == _rating) 
     [tableView cellForRowAtIndexPath:indexPath].accessoryType =UITableViewCellAccessoryCheckmark; 
} 

回答

2

修复了这个问题。我必须返回UITableViewCell返回类型,并且必须使用下面的方法。这是递归调用方法,因此失败了。

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath]; 

    if(indexPath.section == _rating) 
     cell.accessoryType = UITableViewCellAccessoryCheckmark; 

    return cell; 
} 
相关问题