2012-02-28 118 views
1

這是我第一次嘗試使用UINavigationController實現從tableView單元格到另一個tableView的導航,它不適用於我。 我不使用筆尖文件,我有一個簡單的tableView,我在我的應用程序中的一個模式對話框中呈現它,它工作正常,現在我將其中的一個單元添加了revealInidcator,使用戶可以從一個從另一個列表(tableView)可用的固定數量的選項。爲此,我有另一個類,使第二個tableView。現在的問題是從第一個tableview中的單元格(包含披露圖標)導航到第二個tableView不做任何事情,沒有錯誤,沒有任何東西。我想我設置導航控制器的方式是錯誤的,代碼不屬於委託或第二類的數據源。PushViewController什麼都不做

在第一TableView中的方法:didSelectRowAtIndexPath方法我試圖抓住該行,然後調用第二的tableView這樣的:

mySecondViewController *secondVC = [[[mySecondViewController alloc] initWithStyle:UITableViewStyleGrouped ] autorelease]; 
    UINavigationController *navCont = [[UINavigationController alloc] initWithRootViewController: self];//not sure the first controller should act as the root controller? 
[navCont pushViewController:secondVC animated:YES]; //it does nothing, no error,... 

第二tableViewcontroller類包含所有委託和數據源的方法,以及初始化方法:

- (id)initWithStyle:(UITableViewStyle)style 
{ 
    if ((self = [super initWithStyle:style])) { 

    } 
    return self; 
} 

    and declared in interface as: 
@interface stockOptionViewController : UITableViewController { 

} 

我試圖玩viewDidLoad,但沒有幫助。

請幫助我,因爲我沒有線索,並且找到的所有示例代碼均基於使用nib文件。

感謝, 錦

回答

5

你的導航控制器應該是應用程序委託的窗口的根視圖控制器,和第一視圖控制器應該是導航控制器的根視圖控制器,那麼你可以把新的控制器上它。

請參閱文檔UINavigationControlle r。

目前,您正在創建一個導航控制器,但沒有放在任何地方,因此要求它推送新的視圖控制器是沒有意義的。你有正確的代碼,只是沒有正確的順序。

0

UINavigationController應該是根視圖控制器。在當前的代碼中,navCont不在視圖堆棧中,因此它不起作用。將UINavigationController推入堆棧,並將myFirstViewController作爲其根視圖控制器,而不是將myFirstViewController推入您的appDelegate。

0

可以模態呈現視圖控件沒有導航控制器

mySecondViewController *secondVC = [[[mySecondViewController alloc] initWithStyle:UITableViewStyleGrouped ] autorelease]; 
[self presentModalViewController:secondVC animated:YES]; 
+0

它工作正常。謝謝 – Cam 2012-02-28 17:35:30