iPhone one title for all view controllers

最后都变了- 提交于 2019-12-20 05:15:17

问题


I have an app with tab bar controller (with 4 views controller) and it contains a navigation controller. All of this was create programmatically. My question: Is there a way how to set one navigation bar title for all view controllers ? For example: When i switch tabs, title is the same. Ideal solution for me is set title in app delegate file. Thanks a lot


回答1:


If you know that there will be exactly 4 views controller, just do self.title = @"your title"; If you want to change "your title" once and have them all changed, just create a static global or use plist. And put the code under viewDidAppear so that it refreshes every time. No need to do anything too complex :)




回答2:


For all of you, I think you want to put a log there, and it is to set an image file as the tab bar sub view and set the heights of the view controllers less the tab bar image as

UIImageView *navImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:IMG_LOGO]];
//[navImage setCenter:CGPointMake(160, 21)];
[navImage setCenter:CGPointMake(160, 21)];
[self.navigationController.navigationBar addSubview: navImage];
[navImage release];



回答3:


You can create a very basic subclass of UIViewController and set its title. Then, just have your other UIViewController subclasses inherit from this base class instead of directly from UIViewController.




回答4:


Try something like this (i don't have access to Xcode atm so please debug it first):

for (int i = 0; i < [[tabBarController viewControllers] count]; i++) {
    [tabBarController objectAtIndex:i].title = @"This is the title";
}


来源:https://stackoverflow.com/questions/10414806/iphone-one-title-for-all-view-controllers

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!