导航栏标题未设置 iPhone
在我的应用程序中,我呈现了一个模态视图控制器,如下所示,我无法更改导航栏的标题或其任何属性。
fullListTopCompanies *fullListTopCompaniesInstance = [[fullListTopCompanies alloc] initWithNibName:@"fullListTopCompanies" bundle:nil];
UINavigationController *cntrol = [[UINavigationController alloc] initWithRootViewController:fullListTopCompaniesInstance];
[fullListTopCompaniesInstance setTitle:@"TEST"];
UIBarButtonItem *submit = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:@selector(displayViewForPosts)];
fullListTopCompaniesInstance.navigationItem.rightBarButtonItem = submit;
[submit release];
[self presentModalViewController:cntrol animated:YES];
[cntrol release];
我尝试实例化应用程序委托并将其导航控制器分配给本地导航控制器实例,但没有用。
不知何故,导航控制器无法访问。无法使用“self.navigationitem”访问它。每当我将 modalviewcontroller 与导航控制器一起呈现时,该导航都会位于实际导航控制器的下方。
In my app, I'm presenting a modalviewcontroller as follows and I'm not able to change the navigationbar's title or any of its properties for that matter.
fullListTopCompanies *fullListTopCompaniesInstance = [[fullListTopCompanies alloc] initWithNibName:@"fullListTopCompanies" bundle:nil];
UINavigationController *cntrol = [[UINavigationController alloc] initWithRootViewController:fullListTopCompaniesInstance];
[fullListTopCompaniesInstance setTitle:@"TEST"];
UIBarButtonItem *submit = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:@selector(displayViewForPosts)];
fullListTopCompaniesInstance.navigationItem.rightBarButtonItem = submit;
[submit release];
[self presentModalViewController:cntrol animated:YES];
[cntrol release];
I tried instantiating application delegate and assigning its navigationcontroller to local navigationcontroller instance but no use.
Somehow that navigationcontroller is not accessible. It can't be accessed by using "self.navigationitem". Whenever I present modalviewcontroller with the navigationcontroller, this navigation comes below the actual navigationcontroller.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
例如,如果您尝试为名为“ABCViewController”的 ViewController 设置导航栏标题,则
添加self.Title = @"";
在 viewWillAppear 方法中 ABCViewController 并尝试重建并运行。
希望这有帮助。 :)
For Example, if you are trying to set title of navigation bar for the ViewController called "ABCViewController", then add
self.Title = @"";
in viewWillAppear Method of the ABCViewController and try to rebuild and Run.
Hope this helps. :)
这个问题是因为在 self 上调用
presentModalViewController:
,您应该在self.navigationController
上调用它,这样导航控制器就不会显示在另一个控制器的下方。至于为什么不能设置navigationController的属性,我不知道。对我来说看起来不错。但我预计这是因为您在 nib-loader 调用
viewDidLoad
之前设置了属性。我想我自己很久以前就遇到过这样的问题。您应该在
UIViewController
子类的viewDidLoad
方法中设置标题等,我想您的担忧将会结束。That problem is because calling
presentModalViewController:
on self, you should call it onself.navigationController
that way the navigation controller won't be shown below the other one.As to why you can't set the navigationController's properties, I don't know. It looks Ok to me. But I expect it is because you are setting the properties before
viewDidLoad
is called by the nib-loader. I think I remember having problems like this myself a long time ago.You should set the title etc. in the
UIViewController
subclass'sviewDidLoad
method and I think you worries will be over.我使用 xcode 模板创建了一个简单的基于视图的应用程序,然后我添加了您的代码,它对我有用...
}
I've created a simple view based app with xcode template, then i've added your code and it's working for me...
}