UITabBar + UINavigationBar conflict title - iphone

I have a UITabBar and a UINavigationBar created in IB, when I launch my application everytime I navigate the UINavigation title change because I'm using
self.title = #"NAME";
my problem is that the UITabBarItem will change with the same name at the same time.
I want to put a static name only for the UITabBarItem, how to do it in IB or programatically maybe.
Thanks,

try returning an explicit tabBarItem for your controller, and set its title yourself.
- (UITabBarItem *) tabBarItem {
return [[[UITabBarItem alloc] initWithTitle: ...

I find the solution in this adress Stackoverflow navigationItem Title Sorry I didn't find it before posting my question.

try this, in your viewDidLoad
self.tabBarController.navigationItem.title = #"title";

Related

Setting image on tabbar items in special case(if tab bar taken on viewController)

I am taking tab bar controller on view controller rather than delegate, and used code what mentioned below.
tabController = [[UITabBarController alloc]init];
tabController.delegate = self;
scanView = [[ScanTicketView alloc] init];
searchView = [[SearchView alloc] init];
historyView = [[HistoryView alloc]init];
tabController.viewControllers=[NSArray arrayWithObjects:scanView,searchView,historyView, nil];
[self.navigationController pushViewController:tabController animated:YES];
It works, but now how to apply images to these views. Can anyone help me here.
Thanks in advance.
You can use:
viewController.tabBarItem.image = [UIImage imageNamed:#"imageName.png"];
if you want to apply the image only to selected view controller in Tab bar, then UITabBarController has a selectedViewController and a selectedIndex property also see tabBarController.tabBar.selectedItem.tag if this may help.
Tabbar controller has its own property of Image and Title.
Go through this UITabbar Tutorial to understand properly. You can set image through property window or even through coding also.
Best Luck !

How to customize the top bar of a UINavigationController with the current view information?

I've a UINavigationController and in the picture you can see a UIViewController added to it.
Now, I would like to customize the top bar of the UINavigationController with the content of the current visible UIViewController. More in particular, I would like:
add the title
customize "back" button text
Should I use self.navigationController method from the current UINavigationController ? If so, what are the next steps ?
Thanks
You can set the Title with:
[[self navigationItem] setTitle:#"title text"];
You can change the backbuttontext in the InterfaceBuilder or:
[[[self navigationItem] backBarButtonItem] setTitle:#"back button text"];
But remember that the backBarButtonItem comes from the previous ViewController so you have to set it there. Alternatively the title is set from the previous view.
self.title = "Your title";
You can use this in the current view controller for displaying title

Problem with adding UISearch bar

I am trying to implement UISearch bar but I have some problems.
When app starts I add table view like this:
ChannelTableViewRootController *firstViewController = [[ChannelTableViewRootController alloc] initWithStyle:UITableViewStylePlain];
navigationController = [[UINavigationController alloc]initWithRootViewController:firstViewController];
navigationController.navigationBar.hidden = NO;
UIView *uv = self.view;
[uv addSubview:[navigationController view]];
I add UISearch bar in xib. Connect it to UISearchBar variable from my header file. Set delegate to self, and try to add it to header of tableview:
self.tableView.tableHeaderView = searchBar;
searchBar.autocorrectionType = UITextAutocorrectionTypeNo;
And when I make object manually 'searchBar = [[UISearchBar alloc]init]; // + code from above' I got displayed search bar like on image but nothing happends and can't put it over that header. I am trying to make search like in address book with scopes etc.
Have you tried to create the searchbar with the initWithFrame. Try giving Values to it and adding subView to the view not on header. I think you have some mistake in positioning.
You also specified that you added UISearchbar in xib and also you have allocated in the coding also. Dont do that its a wrong way. Do any one of them i suggest you if you add tableView programatically then add searchbar programatically. Or assign them both in Xib.
Otherwise have a look at this tutorial
http://ved-dimensions.blogspot.com/2009/02/iphone-development-adding-search-bar-in.html

Draw custom Back button on iPhone Navigation Bar

I've got a UIView with a NavigationBar and I'd like to add a button which looks like the style of a Back Button. I'm not using a UINavigationController and was wondering if this could be done without it?
The style of the button should look like this:
Thanks
You need to set up a custom stack of UINavigationItem objects and push them on to the UINavigationBar. This is the only way I know of to get a true back button. I haven't tested this code, but you should do something like this:
UINavigationItem *previousItem =
[[[UINavigationItem alloc] initWithTitle:#"Back title"] autorelease];
UINavigationItem *currentItem =
[[[UINavigationItem alloc] initWithTitle:#"Main Title"] autorelease];
[navigationBar setItems:[NSArray arrayWithObjects:previousItem, currentItem, nil]
animated:YES];
To handle when the buttons are pressed you should set yourself as the navigation bar's delegate and implement the UINavigationBarDelegate delegates.
You can also update this by modifying the backBarButtonItem on the previous view controller (not the currently viewed one).

iPhone: Setting Navigation Bar Title

Hey all. I'm still pretty new to iPhone development, and I'm having a bit of trouble figuring out how to change the title of my Navigation Bar. On another question on this site somebody recommended using :
viewController.title = #"title text";
but that isn't working for me...Do I need to add a UINavigationController to accomplish this? Or maybe just an outlet from my UIViewController subclass? If it helps, I defined the navigation bar in IB and I'm trying to set its title in my UIViewController subclass. This is another one of those simple things that gives me a headache. Putting self.title = #"title text"; in viewDidLoad and initWithNibName didn't work either. Anybody know what's happening and how to get it happening right?
Thanks!
The view controller must be a child of some UINavigationController for the .title property to take effect. If the UINavigationBar is simply a view, you need to push a navigation item containing the title, or modify the last navigation item:
UINavigationItem* item = [[UINavigationItem alloc] initWithTitle:#"title text"];
...
[bar pushNavigationItem:item animated:YES];
[item release];
or
bar.topItem.title = #"title text";
if you are doing it all by code in the viewDidLoad method of the UIViewController you should only add self.title = #"title text";
something like this:
- (void)viewDidLoad {
[super viewDidLoad];
self.title = #"title";
}
you could also try self.navigationItem.title = #"title";
also check if your navigationItem is not null and if you have set a custom background to the navigationbar check if the title is set without it.
There's one issue with using self.title = #"title";
If you're using Navigation Bar along with Tab bar, the above line also changes the label for the Tab Bar Item. To avoid this, use what #testing suggested
self.navigationItem.title = #"MyTitle";
If you want to change navbar title (not navbar back button title!) this code will be work.
self.navigationController.topViewController.title = #"info";
If you want to change the title of a navBar inside a tabBar controller, do this:
-(void)viewDidAppear:(BOOL)animated {
self.navigationController.navigationBar.topItem.title = #"myTitle";
}
In my navigation based app I do this:
myViewController.navigationItem.title = #"MyTitle";
I had a navigation controllers integrated in a TabbarController. This worked
self.navigationItem.title=#"title";
By default the navigation controller displays the title of the 'topitem'
so in your viewdidload method of your appdelegate you can. I tested it and it works
navController.navigationBar.topItem.title = #"Test";
UINavigationItem* item = [[UINavigationItem alloc] initWithTitle:#"title text"];
...
[bar pushNavigationItem:item animated:YES];
[item release];
This code worked.
If you are working with Storyboards, you can click on the controller, switch to the properties tab, and set the title text there.
I guess you need a dynamic title that is why you don't set it in IB.
And I presume your viewController object is the one specified in the NIB?
Perhaps trying setting it to a dummy value in IB and then debug the methods to see which controller has the dummy value - assuming it appears as the title...
From within your TableViewController.m
:
self.navigationController.navigationBar.topItem.title = #"Blah blah Some Amazing title";
For all your Swift-ers out there, this worked perfectly for me. It's notably one of the shorter ways to accomplish setting the title, as well:
override public func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "presentLineItem" {
print("Setting Title")
var vc = segue.destinationViewController as! LineItemsTableViewController
vc.navigationItem.title = "Line Item"
}
}