【发布时间】:2016-06-02 06:33:53
【问题描述】:
我有一个带有情节提要和 2 个视图控制器的应用。我已经通过 Appdelegate 以编程方式创建了导航控制器。我在 Viewcontroller1 的viewDidLoad() 中将标题设置为“Screen1”,并添加了一个右栏按钮。
现在,我的问题是,当我单击右栏按钮时,会显示 viewcontroller2,标题设置为“Screen1”,并且右栏按钮也会出现。
注意:在 ViewController2 中,我没有设置任何标题,也没有添加任何条形按钮。
我的代码:
AppDelegate.m: -> didFinishLaunchingWithOptions():
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
VC1 = [[ViewController1 alloc] init];
self.navController = [[UINavigationController alloc] initWithRootViewController:self.VC1];
self.window.rootViewController = navController;
[self.window makeKeyAndVisible];
ViewController1.m -> didViewLoad():
self.navigationItem setTitle:@"first slide"];
UIBarButtonItem *goto2 = [[UIBarButtonItem alloc] initWithTitle:@"Goto to 2" style:UIBarButtonItemStylePlain target:self action:@selector(GotoSlide2)];
[self.navigationItem setRightBarButtonItem:goto2];
-(void) GotoSlide2
{
ViewController2 *vc2 = [[ViewController2 alloc] init];
[self.navigationController pushViewController:vc2 animated:YES];
}
【问题讨论】:
标签: ios objective-c iphone uinavigationbar