我的應用程序是一個帶有許多導航控制器的標籤欄應用程序。 我希望這些導航控制器能夠通過自定義右鍵欄按鈕來處理登錄/註銷操作。所以我成立的AppDelegate我的標籤欄是這樣的:右鍵不會顯示在自定義導航控制器中
MyFirstViewController *firstViewController = [[MyFirstViewController alloc] init];
UIViewController *firstNavigationController = [[CustomNavigationController alloc]
initWithRootViewController:firstViewController];
MySecondViewController *secondViewController = [[MySecondViewController alloc] init];
UIViewController *secondNavigationController = [[CustomNavigationController alloc]
secondViewController]
initWithRootViewController:secondViewController];
....
[tabBarController setViewControllers:@[firstNavigationController, secondNavigationController]];
然後CustomNavigationController
:
@implementation ConnectionNavigationController
- (void) viewDidLoad
{
[self displayConnectionButton];
}
- (void) displayConnectionButton
{
UIImage *portraitImage, *landscapeImage;
portraitImage = [UIImage imageNamed:@"conn.png"];
landscapeImage = [UIImage imageNamed:@"connLandscape.png"];
UIBarButtonItem *connButton = [[UIBarButtonItem alloc]
initWithImage:[portraitImage
imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
landscapeImagePhone:[landscapeImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
style:UIBarButtonItemStylePlain target:self action:@selector(showConnectionPopup)];
self.navigationItem.rightBarButtonItem = connButton;
}
@end
我viewDidLoad
,viewDidAppear
,viewWillAppear
嘗試,但沒有什麼工作,我不能讓這個按鈕在導航欄中顯示。我也嘗試添加reloadInputViews
或setNeedsDisplay
。我該怎麼辦?
感謝您的幫助
編輯:CustomNavigationController的接口
@interface ConnectionNavigationController : UINavigationController
- (void) displayConnectionButton;
@end
您可以添加'@ interface'的'請連接導航控制器? – lucianomarisi
@lucianomarisi我做到了,你會發現裏面沒有很多東西。 – Rob