我有關於UINavigationController的問題。我所做的是,我設置了一個導航控制器來照顧一個視圖控制器,讓它命名爲A.現在我所做的是將一個UIView放在視圖控制器A上,並在該視圖上放置一個tableview。 tableViewcontroller及其代表是在一個獨立的類中定義的。現在我想要做的是當用戶點擊一個表格單元格時,使用「pushViewController」 - 方法推送一個新的視圖控制器。我必須一直將導航控制器的引用傳遞給我的tableview控制器嗎?或者我該如何從tabelviewcontroller類中獲取我的導航控制器?在TableViewController中使用UINavigationController方法
0
A
回答
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
否則,如果你想然後顯示一些代碼! –
相關問題
- 1. 在SKScene中使用TableViewController
- 2. 來自tableViewController子類的UINavigationController pushViewController
- 3. UINavigationController popview方法調用
- 4. 不調用自定義TableViewController tableView()方法
- 5. 覆蓋TableViewController中的init方法
- 6. UINavigationController方法問題
- 7. 無法調用tableViewController
- 8. 在tableViewController中使用多個單元類
- 9. 未在TableViewController中調用willDisplayHeaderView
- 10. 無法投類型的值「TableViewController」到「TableViewController」
- 11. 從類方法訪問UINavigationController
- 12. UINavigationController自定義popViewControllerAnimated方法
- 13. 在另一個UINavigationController中的UITabBarController中使用UINavigationController的問題
- 14. 無法在TableViewController中獲取iAd橫幅
- 15. 在UINavigationController的子視圖中調用的旋轉方法?
- 16. 在tableViewController
- 17. 在TableViewController
- 18. TableViewController和CustomCell使用Swift
- 19. 使用UINavigationController的設備方向
- 20. 如何在UINavigationController中使用UIViewControllerAnimatedTransitioning?
- 21. 在iOS 5中使用UINavigationController設置leftBarButtonItems
- 22. 如何在UINavigationController中使用UIImagePickerController
- 23. 我想在UINavigationController中使用UIPickerImageController嗎?
- 24. 在UINavigationController中,按鈕無法與pushViewController一起使用
- 25. IOS:在UINavigationController中鎖定方向
- 26. 在ios中刷新tableviewcontroller
- 27. UINavigationController中的UIViewController不調用委託方法
- 28. 如何在UINavigationController中觸摸leftBarButtonItem後管理方法?
- 29. 從UINavigationController執行ViewController的方法
- 30. UINavigationController UIBarButtonItem沒有響應動作方法
檢查self.navigationController是否返回tableviewcontroller類中的任何值,如果是的話,那麼它的你想要的導航控制器 – Rajkumar