I have three Views, Splash, Login and List.
From Splash I just wait and then Push Login View, with the Navigation Bar hidden.
In Login I Show the NavigationBar, hide the BackButton1 and add a new RightButton1, then I check if Settings.bundle "login" and "pass" are set. If so, I push List View. Otherwise I stay in the Login view waiting for the user to fill the form and press a button.
In List View I add a new RightButton2 and a new BackButton2.
The problem is that if Settings.bundle data is not null, and in Login View I quickly push List View the RightButton1 appears in List View, or no buttons appear at all, or only BackButton2 doesn't appear...
The most strange thing of all is that everything was OK and all of sudden it started to get messy.
Login View:
// Making the Navigation Bar Visible
[self.navigationController setNavigationBarHidden:NO animated:NO];
// Hiding the Back Button in THIS view (Login)
[self.navigationItem setHidesBackButton:YES];
// Inserting the Logout Button for the Next View (List)
UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
initWithTitle:#"Logout"
style:UIBarButtonItemStylePlain
target:nil
action:nil];
self.navigationItem.backBarButtonItem = backButton;
[backButton release];
UIBarButtonItem* newAccountButton = [[UIBarButtonItem alloc]
initWithTitle:#"New Account"
style:UIBarButtonItemStylePlain
target:self
action:#selector(newAccountButtonPressed)];
self.navigationItem.rightBarButtonItem = newAccountButton;
[newAccountButton release];
List View
// Making the Navigation Bar Visible
[self.navigationController setNavigationBarHidden:NO animated:NO];
UIBarButtonItem* aboutButton = [[UIBarButtonItem alloc]
initWithTitle:#"About"
style:UIBarButtonItemStylePlain
target:self
action:#selector(aboutButtonPressed)];
self.navigationItem.rightBarButtonItem = aboutButton;
[aboutButton release];
Any ideas ?
UPDATE: I've tested more and it seems to me that when I quickly go from Login to List the NavigationBar doesn't have enough time to add the buttons and add the buttons and the bars in the wrong order. I've used a performSelector to make Login view wait until push List and if the Delay is like 2secs, everthing goes fine, but if it is like 0.1secs the problem appears again.
I'm usign viewDidLoad.. How can I make the Login View only push the List View after everything in it's NavigationBar is already ok? In other words, how can I make the push wait all the previous commands without a delay with fixed timing ?
One thing to consider is making your splash screen a modal view controller, since you're having to do a lot of extra work to make it not appear in the navigation hierarchy. Just use the presentModalViewController:animated: method of your navigation controller.
It may make sense to make the login view modal as well.
Better still, use default.png as your splash screen, and pop up a modal view controller for login. That is assuming your splash screen is static.
Related
Here is what I did, this is a dynamic questionary application;
-Created a UINavigationBased application
-Created some new UIVIewController subclasses with their xib's and designed them.
-I opened mainwindow.xib and set the navigationcontroller to has a navigation bar and a toolbar in black.
-So now when I switch back and forth between views by pushing them with the navigation controller I can see that shared toolbar and a navigationbar in every page with a backbutton, which is cool.
some of my uiviews are tableviews and some are textboxes
What I want is I want to put a "next" button on that toolbar and be able to go through my views but not with getting the row tap. With each next click I will decide which view to push.
How can I put this "shared" button? and in which class can I define its functionality? also I want to make it sometimes invisible for instance on first page and on last page of questionary.
In every page that you want to have a next button add this in the init or viewDidLoad
UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithTitle:#"Next"
style:UIBarButtonItemStylePlain
target:self
action:#selector(pushNextView)];
self.navigationItem.rightBarButtonItem = rightButton;
[rightButton release];
Now just implement pushNextView method to push what ever view you want
-(void)pushNextView{
//push next view
}
Edit
By specifying the target of your rightButton to AppDelegate (right now it points to self) you can setup the pushNextView method in your AppDelegate and manage all your views there.
I have a navigation view controller and there are 3 view controllers in the navigation stack. Now on the third and top most visible view controller I have a default back button coming in.
I need to bring this view controller in edit mode which I did... Now the requirement is to have a cancel button as the left bar button item instead of back button.
This is similar to the functionality given by contacts application of iPhone where you edit a particular contact.
Any clue how to achieve this?
To hide back button and add a left bar button use-
[self.navigationItem setHidesBackButton:TRUE];
UIBarButtonItem *leftBarButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:#selector()];
[self.navigationItem setLeftBarButtonItem:leftBarButton];
[leftBarButton release];
And then to programmatically return to the previous view controller, you can do-
[self.navigationController popViewControllerAnimated:YES];
This is a simpler way:
[self.navigationItem setHidesBackButton:YES];
If you are using storyboard, you can also just drag a bar button item onto the navbar where the back button would normally show up. This will override it.
I have a UINavigationController that I've set as the rootViewController of my window. In the NIB file I've set it up so that it has a "Bottom Bar" of "Toolbar". In Interface Builder I've added a UIBarButtonItem. This all works great and I can handle the button click fine. When I hit one of the buttons, I push a new view onto the ViewController and that works fine too. One problem, my button disappears when the view is loaded. Now in the subsequent view I can set the bottom bar to be a Toolbar and I see it in Interface Builder, but I cannot add any buttons to it.
I know I'm either missing something obvious or thinking about this incorrectly but how do I add UIBarButtonItems to subsequent views pushed to my nav controller? I'm talking the bar at the bottom, not the nav bar at the top.
Any ideas?
The toolbarItems property on the UIViewController is what you are interested in. You can create UIBarButtonItems programmatically and add them to a new toolBarItems array in viewDidLoad.
- (void)viewDidLoad {
[super viewDidLoad];
UIBarButtonItem* editButton = [[[UIBarButtonItem alloc] initWithTitle:#"Edit" style:UIBarButtonItemStyleBordered target:self action:#selector(editAction)] autorelease];
[self setToolbarItems:[NSArray arrayWithObject:editButton]];
}
This worked better for me:
[[self navigationItem] setLeftBarButtonItem:homeButton];
You can do the same for the right side.
I came across a very subtle issue.
Usually things are okay, but occasionally the current UIviewController has no title. When I call another viewcontroller called via
[[fruitDB navigationController] pushViewController:fruitc animated:YES];
there is no "back" button. The area on the top left of the navigation bar is still active though and I can go back.
How can I make sure the back button is still active, even if there is no title?
you can set the backBarButtonItem of the navigation item of the view controller.
Specifically, somewhere in viewController1 before pushing viewController2, do the following...
self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBarButtonItemStylePlain target:nil action:nil] autorelease];
When you push viewController2, the back button shown will be the backBarButtonItem of viewController1.
Note: Technically, apple recommends overriding the navigationItem method in your view controller, and adding buttons there, but it's really not an issue in your case.
Just before you push the next view controller why don't you try:
self.title = #"Back";??
I have a reference to a "UIBarButtonItem", is there a way I can add a custom "Back Navigation Button" to that item when it is not part of a Navigation based view?
I can add a left button:
UIBarButtonItem *backButton = [[UIBarButtonItem alloc]
initWithTitle:#"Custom Back"
style:UIBarButtonItemStylePlain target:self
action:#selector(backAction:)];
menuItem.backBarButtonItem = backButton; //This doesn't seem to work.
menuItem.popOverNavigationItem.leftBarButtonItem = backButton; //This shows a normal button
So how could I make the leftmost button look like a back navigation button?
UPDATE: This other question answered the root of my problem that was leading me to try and do this non-standard UI setup:
iPad: Merge concept of SplitViewController and NavigationController in RootView?
I think the correct way to set the back button is to set it for the view controller that you would be going back to. For example:
RootViewController > DetailViewController
If you want the back button to say "Custom Back" whilst you're on DetailViewController, you have to actually set RootViewController's back button to "Custom Back".
Hope that makes sense.
Having just struggled with this: I think the answer is “no.” You'll need a controller hierarchy.