2010-02-05 37 views
2

在我的tableview中,我有許多具有公開詳細按鈕附件類型的行,並且當按下行或附件時,新視圖被推送到導航控制器。我在didSelectRowAtIndexPath函數的末尾調用deselectRowAtIndexPath。AccessoryDe​​tailDisclosureButton在我打電話後取消選擇取消選擇RowAtIndexPath

如果我按下附件按鈕,我會進入一個新視圖,但是當我回到這個視圖(彈出)時,它仍然會高亮顯示。該行按預期取消選擇,但不是這樣。有關如何「不高興」的想法?

cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton; 

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 
    ... 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 

    } 
    - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { 
    [tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionTop]; 
    [self tableView:tableView didSelectRowAtIndexPath:indexPath]; 
    } 

回答

1

只要從

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath; 

方法去除聲明

[tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionTop]; 

既然你的表已經允許的選擇,而你正確地取消它

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; 

你完成了,因爲當按下披露按鈕時該行將被突出顯示,並且在執行tableView:didSelectRowAtIndexPath:時取消選擇。

+0

這可以取消選擇附件,但是當按下附件按鈕時整行不會突出顯示。有什麼辦法可以做到這一點? – Rob 2010-02-07 23:39:39

+0

你是對的,行沒有突出顯示。但是,Apple HIG在點擊披露按鈕時並未強制突出整行。我所有的應用程序都按照所述的方式工作,包括在AppStore上提供的應用程序。 – 2010-02-08 12:43:52

+0

夠公平的,謝謝你的幫助。 – Rob 2010-02-09 04:21:13

3

對於那些誰仍然被這個困擾,並希望出現現在工作的解決方案,試試這個:

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath { 

[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone]; 
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone]; 

} 

必須重新加載數據,然後再選擇該行,這樣的亮點出現下你的行動表選項。

+0

'-reloadRowsAtIndexPaths:withRowAnimation:'的第二個參數不是'BOOL';它是一個'UITableViewRowAnimation'類型 – user102008 2011-04-27 23:44:05