2011-06-14 93 views
0

我有viewcontroller與表視圖,當我點擊一個單元格我去導航到另一個視圖控制器與另一個tableview。uitableview的問題,當返回

我嘗試在第一個viewcontroller中使用viewDidAppear和viewWillAppear,當我從第二個viewcontroller回到這個viewcontroller時,我會輸入這個方法之一。

問題是當我返回到這個viewcontroller時他沒有進入這個方法。

這是我如何進入第二視圖控制器:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
     ProfileViewController2 *tmp = [[ProfileViewController2 alloc]initWithType:indexPath.row string:[self.array2 objectAtIndex:indexPath.row]]; 
     [[self navigationController] pushViewController:tmp animated:YES]; 
     [tmp release]; 
     [self.mytableview deselectRowAtIndexPath:indexPath animated:YES]; 
    } 
+0

'viewWillAppear:'應該被調用。你想在'viewWillAppear:'中做什麼,以及你是如何返回到第一個視圖控制器的。 – 2011-06-15 00:59:06

回答

0

viewWillAppearviewDidAppear是出了名iOS上不穩固。

如果您正在使用UITableView s工作,我們總是把我們所需要的表被加載到

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 

功能之前運行的代碼。這是一個輕微的黑客攻擊,但工作得很好,因爲這是所調用的UITableViewDataSource協議的第一個功能。

或者,你可以調用

[tmp viewDidAppear]; 

推視圖控制器後,釋放tmp迫使被調用函數之前。