我使用XCode的Master/Detail模板编写了Master/Detail应用程序.启动应用程序后,主视图的导航按钮标题只是"主".现在我想重命名那个按钮,但不幸的是我不知道如何访问这个按钮.在appdelegate.m中,有以下代码来初始化视图:
MasterViewController *masterViewController = [[MasterViewController alloc] init];
UINavigationController *masterNavigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
UINavigationController *detailNavigationController = [[UINavigationController alloc] initWithRootViewController:detailViewController]
Run Code Online (Sandbox Code Playgroud)
我尝试了这些方法没有成功:
masterViewController.navigationItem.title = @"newTitle";
Run Code Online (Sandbox Code Playgroud)
要么
masterNavigationController.navigationItem.title = @"newTitle";
Run Code Online (Sandbox Code Playgroud)
由于我不确定,如果按钮的名称只是idt后面的视图的标题,我也尝试过:
masterViewController.title = @"newTitle";
没有任何效果.但由于按钮的标题是"Master",我绝对没有设置它,我相信必须有一些方法来设置它.有谁知道怎么做?
只是为了显示按钮: