2011-08-25 25 views
1

我的導航欄中有2個視圖View1View2View1tableView。所以我想要做的是deselectRow when I come back from View2 to View1`。這工作正常,如果只是這樣做:iPhone:重新加載後取消選擇RowAtIndexPath

- (void)viewWillAppear:(BOOL)animated { 
    NSIndexPath *myIP = [NSIndexPath indexPathForRow:0 inSection:0]; 
    [self.tableView deselectRowAtIndexPath:myIP animated:NO]; 

}

而且我需要重新加載該行。但是,如果調用reloaddeselect不工作:

- (void)viewWillAppear:(BOOL)animated { 
    self.navigationController.navigationBarHidden = NO; 

    NSIndexPath *myIP = [NSIndexPath indexPathForRow:0 inSection:0]; 
    [self.tableView deselectRowAtIndexPath:myIP animated:NO]; 
    [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:myIP] withRowAnimation:UITableViewRowAnimationNone]; 
} 

我也試圖selectdeselect它,這樣的作品,但問題是,我打開視圖1在第一時間或從另一種觀點,我看取消動畫

- (void)viewWillAppear:(BOOL)animated { 
self.navigationController.navigationBarHidden = NO; 

NSIndexPath *myIP = [NSIndexPath indexPathForRow:0 inSection:0]; 

[self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:myIP] withRowAnimation:UITableViewRowAnimationNone]; 
[self.tableView selectRowAtIndexPath:myIP animated:NO scrollPosition:UITableViewScrollPositionNone]; 
[self.tableView deselectRowAtIndexPath:myIP animated:NO]; 

} 

有什麼建議嗎?在此先感謝...

回答

0

在跳轉到新視圖之前,您是否可以不取消選擇didSelectRowAtIndexPath中的行:(對於視圖1)?這樣你就不用擔心在返回時取消選擇它。這就是我通常所做的。

+0

(更新我的答案,使用選擇方法的表格行) – Simon

+0

這通常是這樣做的方式。正如Simon所說的,只需添加[self.tableView deselectRowAtIndexPath:indexPath.row];到您的didSelectRowAtIndexPath tableView委託方法的末尾。 –

0

通常在從一個視圖向另一個視圖移動時,如果第一視圖是表視圖然後在表視圖delagate源會有方法「didSelectRowAtIndexPath方法:」此方法下,我們將調用的類和在呼叫有兩種類型 1.使用PresentModalViewController - 它會像導航和使用後退按鈕的第一個視圖可以調用。 2.使用PushViewController - 它將移動到下一個視圖並返回到相同的視圖,我們必須再次添加一個IBACTION按鈕並使用dismiss模式視圖控制器。

這是速滑運動員的肌肉兩種觀點的運動方法.....

0

我同意,移動到下一個視圖之前取消行聽起來像你最好的選擇,但是,我發現,這是更好地取消行中的viewDidDisappear方法,像這樣:如果你正在改變細胞的任何格式,當他們選擇,如更改行高度

- (void)viewDidDisappear:(BOOL)animated 
{ 
    NSIndexPath *selected = [self.tableView indexPathForSelectedRow]; 
    if (selected) [self.tableView deselectRowAtIndexPath:selected animated:NO]; 

    [self.tableView beginUpdates]; 
    [self.tableView endUpdates]; 
} 

最後兩個代碼的行會有所幫助。如果選定/未選定行的格式保持不變,則可以忽略這兩行。

相關問題