2012-09-27 87 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; 
} 
相關問題