2012-09-27 37 views
0

我有關於UINavigationController的問題。我所做的是,我設置了一個導航控制器來照顧一個視圖控制器,讓它命名爲A.現在我所做的是將一個UIView放在視圖控制器A上,並在該視圖上放置一個tableview。 tableViewcontroller及其代表是在一個獨立的類中定義的。現在我想要做的是當用戶點擊一個表格單元格時,使用「pushViewController」 - 方法推送一個新的視圖控制器。我必須一直將導航控制器的引用傳遞給我的tableview控制器嗎?或者我該如何從tabelviewcontroller類中獲取我的導航控制器?在TableViewController中使用UINavigationController方法

+0

檢查self.navigationController是否返回tableviewcontroller類中的任何值,如果是的話,那麼它的你想要的導航控制器 – Rajkumar

回答

1

在你單獨UITableViewclass說(yourTableView),您有UITableViewDelegates,聲明屬性id delegate; 從你的viewController說A,主體在yourTableView.delegate = self;

也許didSelectRowAtIndexPath of yourTableViewClass for push on didSelect as always create new instance of newController to be push(eg newController) finally ..

[delegate.navigationController pushViewController:newController animated:YES]; 

這裏'委託'原來是viewController A,你已經分配了一個UINavigationController。 希望這個工程

1

這是我能夠工作的tutorial

我還閱讀關於主題的官方SDK文檔:Combining Tab Bar and Navigation Controllers。由於我還在學習,tutorial幫助我比文檔更多。

別的試試這個代碼

- (void)applicationDidFinishLaunching:(UIApplication *)application { 

// Create instance of UINavigationController 
UINavigationController *myNavigationController; 
// Create initialized instance of UITabBarController 
UITabBarController *tabBarController = [[UITabBarController alloc] init]; 
// Create initialized instance of NSMutableArray to hold our UINavigationControllers 
NSMutableArray *tabs = [[NSMutableArray alloc] init]; 

// Create first UIViewController 
UIViewController *myFirstViewController = [[UIViewController alloc] init]; 
[myFirstViewController setTitle:@"First"]; 
// Initialize the UINavigationController 
myNavigationController = [[UINavigationController alloc] initWithRootViewController:myFirstViewController]; 
// Add UINavigationController to you tabs 
[tabs addObject:myNavigationController]; 
// Release UIViewController and UINavigationController 
[myFirstViewController release], [myNavigationController release]; 

// Create second UIViewController 
UIViewController *mySecondViewController = [[UIViewController alloc] init]; 
[mySecondViewController setTitle:@"Second"]; 
// Initialize the UINavigationController 
myNavigationController = [[UINavigationController alloc] initWithRootViewController:mySecondViewController]; 
// Add UINavigationController to you tabs 
[tabs addObject:myNavigationController]; 
// Release UIViewController and UINavigationController 
[mySecondViewController release], [myNavigationController release]; 

// Add the tabs to the UITabBarController 
[tabBarController setViewControllers:tabs]; 
// Add the view of the UITabBarController to the window 
[self.window addSubview:tabBarController.view]; 
} 
+0

否則,如果你想然後顯示一些代碼! –

相關問題