我有一個應用程序,從AppDelegate創建一個tabbarcontroller。我想要一個按鈕添加到導航欄,但無法。最終我設法得到了一些有效的代碼,但我並不真正瞭解它。爲什麼重寫navigationController:willShowViewController:動畫必要的標籤欄
的步驟是:
- 確認的AppDelegate中以UINavigationControllerDelegate
- 設置rootNavigationController.delegate =自
- 覆蓋navigationController:willShowViewController:動畫和tabBarController:didSelectViewController
我想我遵循tabBarController:didSelectViewController代碼,但我迷失在與發生了什麼navigationController:willShowViewController:動畫。
- (void) tabBarController: (UITabBarController*) tabBarController didSelectViewController: (UIViewController*) viewController
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
self.tabBarController.navigationItem.title = viewController.navigationItem.title;
self.tabBarController.navigationItem.rightBarButtonItems = viewController.navigationItem.rightBarButtonItems;
self.tabBarController.navigationItem.leftBarButtonItems = viewController.navigationItem.leftBarButtonItems;
}
}
- (void) navigationController: (UINavigationController*) navigationController
willShowViewController: (UIViewController*) viewController
animated: (BOOL) animated
{
if (viewController == tabBarController)
{
UIViewController* tabViewController = tabBarController.selectedViewController;
SEL willShowSel = @selector(navigationController:willShowViewController:animated:);
if ([tabViewController respondsToSelector: willShowSel])
{
UIViewController<UINavigationControllerDelegate>* vc =
(UIViewController<UINavigationControllerDelegate>*) tabViewController;
[vc navigationController: navigationController willShowViewController: vc animated: animated];
}
}
感謝您的意見,我會認爲這是一個相當標準的設計 - 標籤欄是頂級和帶按鈕的導航欄 – ardochhigh
我認爲它比這更簡單:意圖出現將按鈕添加到TBC的導航欄,但TBC沒有導航欄;只有子控制器可以。 –