我使用 XCode 的 Master/Detail 模板编写了一个 Master/Detail 应用程序。启动应用程序后,主视图的导航按钮的标题只是“Master”。现在我想重命名该按钮,但不幸的是我不知道如何访问该按钮。
在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]
我尝试了这些方法但没有成功:
masterViewController.navigationItem.title = @"newTitle";
or
masterNavigationController.navigationItem.title = @"newTitle";
由于我不确定按钮的名称是否只是 idt 后面视图的标题,我也尝试过:
masterViewController.title = @"newTitle";
什么都没起作用。但由于按钮的标题是“Master”,而且肯定不是我设置的,所以我相信一定有办法设置它。有谁知道该怎么做?
Just to show the button:
If you would have created Master/Detail application using Master/Detail Template, then go to your "MasterViewController.m"
file and change the string "Master" as you wanted. See the below image it would be like this in your MasterViewController.m
.
![enter image description here](https://i.stack.imgur.com/EKfAj.png)
UPDATE:
and also change the barButtonItem
name in the DetailViewController.m
as like below. This will do the trick.
![enter image description here](https://i.stack.imgur.com/fIpeX.png)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)