2009-09-22 40 views
2

我在下面的代碼來實現這一點。問題有選在一個UITableViewCell

UITableViewCell *cell = [tableView1 cellForRowAtIndexPath:indexPath]; 
UITableViewCell *cell2 = [tableView1 cellForRowAtIndexPath:oldIndexPath1]; 

cell.accessoryType = UITableViewCellAccessoryCheckmark; 
cell2.accessoryType = UITableViewCellAccessoryNone; 
oldIndexPath1 = indexPath; 

但是,如果我選擇,然後取消選擇複選標記,然後我不能選擇對號了。

你能幫助我嗎?

+2

倘使你在didSelectRowAtIndexPath方法發佈的代碼()。 – Jordan 2009-09-22 12:10:35

回答

6

我想你混淆改變從一個到另一個檢查,只有切換一個單元的動作的動作。

假設你只想要一個勾選電池,你可以做到以下幾點:

+(void)toggleCheckmarkedCell:(UITableViewCell *)cell 
{ 
    if (cell.accessoryType == UITableViewCellAccessoryNone) 
     cell.accessoryType = UITableViewCellAccessoryCheckmark; 
    else 
     cell.accessoryType = UITableViewCellAccessoryNone; 
} 

// tableView:didSelectRowAtIndexPath: 

UITableViewCell *cell = [tableView1 cellForRowAtIndexPath:indexPath]; 
UITableViewCell *cell2 = [tableView1 cellForRowAtIndexPath:oldIndexPath1]; 

// Toggle new cell 
[MyController toggleCheckmarkedCell:cell]; 
if (cell != cell2) // only toggle old cell if its a different cell 
    [MyController toggleCheckmarkedCell:cell2]; 
oldIndexPath1 = indexPath;