UINavigation controller back title is ignores previous title - iphone

I would like my navigation controller to act the way that ios7 does = display the previous view title.
It doesn't always work for me
I have a SettingViewController :
- (void)viewDidLoad
{
self.navigationItem.title = NSLocalizedStringFromTableInBundle(#"account_settings", nil,[GeneralUtil getLangBundle],nil);
self.navigationController.navigationBar.translucent = NO;
[super viewDidLoad];
}
When clicking on a button it opens the Profile Picture view controller like this:
UIViewController *vc = [[UIStoryboard profilePictureStoryBoard]instantiateInitialViewController];
[self.navigationController pushViewController:vc animated:YES];
The profile picture is opened successfully but the title of the back button is Back and not the title of the Settings View controller which is Settings.
What could be the problem?

The back button changes its text in iOS 7 depending on the length of the title it needs to display.
If the name of the previous viewcontroller is too long to fit, it will instead just say 'Back'. If there's not even enough room for 'Back', it will just show the arrow.

Related

Want to create logout button in tabbar

I have created an application that have 9 screen and I have added tabbar in it which contain 4 baritem.
Now I have two problems -
1 => My last baritem is logout button, I don't want to display view controller for it, simply when user click this button then alertview should pop up and ask for logout and if user says yes then it will logout.
2=> How to display tabbar in that view controller that does not added in tabbar, because I have 9 screen and only 4 screen display in tabbar.
UPDATE
I said that I have 9 view controller in my app
like...
firstViewController
secondViewController
thirdViewController
fourViewController
|
|
ninthViewController
But my tabbar have only four view controller in baritem which are -
firstViewController
secondViewController
thirdViewController
fourViewController
Now, my other view controller does not display tabbar.
I dont know this is right way or not but you can do it like this...
first read this question that show how to display login and come back to home.
Now add this code in didFinishLaunchingWithOptions method
UIViewController * logoutVC =[[UIViewController alloc] init];
NSArray *viewControllersArray = [[NSArray alloc] initWithObjects:firstView, secondView, thirdView,logoutVC, nil];
self.tabController = [[UITabBarController alloc] init];
[self.tabController setViewControllers:viewControllersArray animated:YES];
[self.window addSubview:self.tabController.view];
And implement this delegate method of tabbar
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
//select the index where your logout button is
if ([tabBarController selectedIndex] == 3) {
NSLog(#"logout");
self.tabController.selectedViewController = fistView; //firstview is your home screen
//LOGOUT
LoginViewController * vc = [[LoginViewController alloc] initWithNibName:#"LoginViewController" bundle:nil];
vc.delegate = self;
[self.tabController presentModalViewController:vc animated:NO];
}
}
Your first question:
Don't do this, it's an abuse of tab bar controller. Each item on the tab bar controller should be a different view in your app, not an action. Find an appropriate place for a logout action button.
Your second question:
There are several ways to show a view controller that isn't one of the main VCs for the tab bar controller. It could be reached by:
being shown as a modal screen
as a popover
Update
To show a 'secondary' view controller that isn't a main VC of the tab bar, but still have the tab bar visible, you can present that secondary VC as a sub-viewcontroller of a main tab bar VC. In other words, present the view of your secondary VC as a subview of a main VC view.

displaying navigation bar when switching to another view

I have a button when it pressed, I want it to take me to another view (the "news" view). Within the news view, I want there to be a navigation bar with a back button. I have a navigationcontroller setup throughout my app but I can't seem to get this to work when this button is pressed. It takes me to the view I want but there is no navigation bar and no back button. This is my code that is implemented when the button is pressed.
If anybody know what I am doing wrong, it would be much appreciated.
Thanks
-(IBAction)news
{
newsViewController *view1 = [[newsViewController alloc] initWithNibName:#"newsViewController" bundle:nil];
view1.title=#"news";
[self.navigationController pushViewController:view1 animated:YES];
}
I am not in my mac, so I can not test code, but if it is working and the only issue you got is not show the bar, what you need to is set the bar to be visible:
From apple docs:
The navigation toolbar is hidden by default but you can show it for
your navigation interface by calling the setToolbarHidden:animated:
method of your navigation controller object. If not all of your view
controllers support toolbar items, your delegate object can call this
method to toggle the visibility of the toolbar during subsequent push
and pop operations.
Something like that is supposed to work:
-(IBAction)news {
newsViewController *view1 = [[newsViewController alloc] initWithNibName: #"newsViewController" bundle:nil];
view1.title=#"news";
[self.navigationController pushViewController:view1 animated:YES];
//Add this line!
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
I hope it can help you.
write the below code in page where you want to show navigation controller
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = NO;
}

iphone is there a way to create a view over the tabbar?

I have an application that pulls up a login page when it first starts. This login page goes over the application and does not let anyone through until they've logged in. I also have a settings tab on my main application that needs to lead back to this login screen. Right now it displays the login screen with the tab bar over it. Is there a way to get the login view over the tab bar?
I've done something similar by having views transitioning in over the top of my tab bar. I used yourView.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; with a 'close' button to let users return to the tab bar screen. I've not done this so it automatically comes in on app fire-up but instead call the view from a button on the screen separate to the tab bar controls. However, I'm sure you'll be able to utilise this somehow to do what you want.
In fact I've actually used this way of calling up views all over my app, each time it covers the tababr and you have to 'close' it to get back to main tabbed navigation you came from.
Try setting below in your viewDidLoad of login screen:
self.tabBarController.hidesBottomBarWhenPushed = YES;
You can do this by using a subclass of UITabBarController, which then performs various checks in viewDidAppear:. The login view is modally presented, as #Maxwell suggested.
// a subclass of UITabBarController
- (void) viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self firstLoadChecks];
}
- (void) firstLoadChecks
{
if (!self.hasLogin) {
id login = [[[LoginViewController alloc] initWithDelegate:self autorelease];
id nav = [[[UINavigationController alloc] initWithRootViewController:login] autorelease];
nav.modalPresentationStyle = UIModalPresentationStyleFormSheet;
nav.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
[self presentModalViewController:nav animated:YES];
}
}
// from LoginViewControllerDelegate
- (void) didLogin
{
self.hasLogin = YES;
[self dismissModalViewControllerAnimated:YES];
}
// my LoginViewController can be closed without a login
- (void) dismissModalViewControllerAnimated:(BOOL) animated
{
[super dismissModalViewControllerAnimated:animated];
[self firstLoadChecks];
}

button does not show up in navigationBar item

I've created a project with Navigation-based Application template, and did some work and ran it.
I expected if I touch a cell, new view will show up and new icon (which is going back button) will show up on navigation-bar item too.
But for some reason, the 'back button' is not added automatically. What can be the problem??
Below is my code.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic may go here -- for example, create and push another view controller.
MessageView *detailViewController = [[MessageView alloc] initWithNibName:#"MessageView" bundle:nil];
NSDictionary* aMessage = [m_tableData objectAtIndex:indexPath.row];
detailViewController.m_message = [[NSDictionary alloc] initWithDictionary:aMessage];
// Pass the selected object to the new view controller.
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
}
You probably haven't given your parent controller a title (just self.title = #"my name" in viewDidLoad or viewWillAppear). That's what gets filled in by default in the back button, so if you don't name it, you don't get a back button.
You are saying that MessageView is inherited from UIView. But I think if there's no problem to push into the navigation controller then it would be UIViewController's subclass.
There are some reasons for not displaying back button:-
1.) As Mackworth told that you have not given any title from which you are navigating.
2.) your Navigation Bar's back button property is set for hidden.
Otherwise back button should be appear on the navigation bar.
It seems you haven't set your Navigation Bar Title in the View from where you are navigating...
Once you set the title of navigationbar by default it will show you the back button
Use it in either ViewDidLoad or ViewWillAppear.
self.navigationItem.title=#"Set Your Title here";

strange behavior when changing UINavigationController backItem title

I'm changing the back button item title in the viewDidAppear of a controller in the following way:
self.navigationController.navigationBar.backItem.title = #"Previous";
It changes the tittle properly, but the I'm having a strange behaviour. When I select the "previous" button, it changes the tittle of the controller that is up in the stack (i.e the parent controller now has the title "Previous".
Do you now why this happened?
When you're using a navigation controller, calling [self setTitle:#"Title"]; inside of any view controller in the stack will set the navigation bar title. This is also the title used by default for the back button when you've pushed a new view controller. Apparently, from what you are experiencing, explicitly setting the title of the backItem, also sets it for the navigation bar title for the previous view controller overriding whatever what specified in the call to -setTitle in the view controller.
You will probably be better off just managing the title from within the view controllers in your navigation stack. When you go to push a new view controller, do this:
[self setTitle:#"Previous"];
NextViewController *controller = [[NextViewController alloc] init];
[[self navigationController] pushViewController:controller animated:YES];
[controller release], controller = nil;
Now, when the next view controller displays, the back button with say "Previous". Now, you just need to change it back to whatever its real title should be in -viewWillAppear:
- (void)viewWillAppear:(BOOL)animated;
{
[self setTitle:#"Real Title"];
[super viewWillAppear:animated];
}
It may feel a little hacky, but it's better than trying to override the navigation bar functionality. Wrestling with the nav bar/nav controller stack can prove very frustrating.
Best regards.