Master/Detail 应用程序中的 NavigationItem [英] NavigationItem in Master/Detail application
问题描述
我使用 XCode 的 Master/Detail 模板编写了一个 Master/Detail 应用程序.启动应用程序后,主视图的导航按钮的标题只是主".现在我想重命名那个按钮,但不幸的是我不知道如何访问这个按钮.在 appdelegate.m 中有以下代码来初始化视图:
I wrote a Master/Detail Application by using the Master/Detail template of XCode. After starting the app, the title of the navigation button for the master view is just "Master". Now I waant tio rename that button, but unfortunately I don't know how to access this button. In appdelegate.m there is the following code to initialize the views:
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]
我尝试了这些方法都没有成功:
I tried these ways without success:
masterViewController.navigationItem.title = @"newTitle";
或
masterNavigationController.navigationItem.title = @"newTitle";
因为我不确定,如果按钮的名称只是 idt 后面的视图的标题,我也尝试过:
As I wasn't sure, if the name of the button is just the title of the view behind idt, I also tried that:
masterViewController.title = @"newTitle";
masterViewController.title = @"newTitle";
没有任何效果.但是由于按钮的标题是Master",我绝对没有设置它,我相信一定有某种方法可以设置它.有人知道怎么做吗?
Nothing worked. But as the title of the button is "Master" and I definitely didn't set it, I believe there must be some way to set it. Does anyone know how to do it?
只是为了显示按钮:
推荐答案
如果您想使用 Master/Detail Template 创建 Master/Detail 应用程序,请转到您的 "MasterViewController.m"
文件并根据需要更改字符串Master".见下图,它在你的 MasterViewController.m
中是这样的.
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
.
更新:并更改 DetailViewController.m
中的 barButtonItem
名称,如下所示.这将解决问题.
UPDATE:
and also change the barButtonItem
name in the DetailViewController.m
as like below. This will do the trick.
这篇关于Master/Detail 应用程序中的 NavigationItem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!