Is it possible to set self.navigationItem.title = @"MyTitle";
after the view has loaded ?
I am using a search bar and in the same view I feed a UITableView using the search results. So I want to set the search bar's text value as the title of the navigation bar, after the search results loaded.
I am using iOS 4.3.
Just set the title of UINavigationBar
like this:
navBar.topItem.title = @"sample string";
Found a solution. I followed Pedro Valentini's post.
This is what I did,
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 120, 30)];
label.textAlignment = UITextAlignmentCenter;
[label setFont:[UIFont boldSystemFontOfSize:16.0]];
[label setBackgroundColor:[UIColor clearColor]];
[label setTextColor:[UIColor whiteColor]];
[label setText:text];
[self.navigationController.navigationBar.topItem setTitleView:label];
[label release];
Normally the titleView will be an UILabel, so you can fetch it, cast it, and set its text.
For some reason I had problems using this in viewDidLoad
, adding it to viewWillAppear
seemed to do the trick.
((UILabel *)self.navigationController.navigationBar.topItem.titleView).text = @"your title here"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With