2012-03-12 73 views
0

我有一個UITableiew,我希望能夠顯示一個自定義複選標記,當該行被選中(點擊),但是,如果有任何其他的複選標記行,它必須被隱藏。做這個的最好方式是什麼? IF ...似乎根本不起作用,它不會像我想的那樣隱藏和取消隱藏複選標記。如何隱藏表視圖中的自定義複選標記

在此先感謝。 - 保羅。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{  
    home_2_CustomCell *cell = (home_2_CustomCell*)[tableView cellForRowAtIndexPath:indexPath]; 

    //This will hide the selected row... 
    cell.imageViewDidSelectRow.hidden = YES; 

// if (cell.imageViewDidSelectRow.hidden = NO){ 
//  cell.imageViewDidSelectRow.hidden = YES; 
// } 

} 
+0

在這裏找到答案:http://stackoverflow.com/questions/5959950/iphone-uitableview-cellaccessory-checkmark – 2012-03-13 01:57:09

回答

0
1) Maintain a tag in class level as an NSIndexPath variable. 
2) Whenever a cell is selected make note of the indexPath and reload the table view. 
3) In cellForRowAtIndexPath delegate check for this variable and set marks accordingly. 
4) This will not be costly if you have the cell with less information. 
+0

由於所有的數據都是我的核心數據實體的一部分,是否有意義在實體中跟蹤它爲一個新的BOOL屬性,然後解析這些值,在選擇行時修改對象? – 2012-03-12 19:27:11

0

可以通過此代碼 的UITableViewCell得到的tableview的每個小區*細胞= [product_table的cellForRowAtIndexPath:[NSIndexPath indexPathForRow:clickedTag切入口:0]]; 做一個循環。

for(int i=0;i<[tabledata count];i++){ 
cell.imageViewDidSelectRow.hidden = YES; 
} 

對於每個單元格,除了當前行被選中,並且您只有一個圖像顯示爲當前行。

相關問題