I am new to Objective-C, can anyone tell me how to get this kind
of back button on the navigation bar, on click of that it should navigate to previous page.
It is default back button style of Navigation-based application.
You can use it by selecting Navigation-based application when creating new application.
After created the application, you must set title of the view.
That view title will be the title of back button.
If you have no title of previous view, the back button will not appear automatically.
You can push view like this:
if (settingViewController == nil) {
settingViewController = [[SettingViewController alloc] initWithNibName:#"SettingViewController" bundle:nil];
}
[self.navigationController pushViewController:settingViewController animated:YES];
In this case, navigationController is already created by Xcode and you must prepare settingViewController(.h, .m, .xib).
Try this ..
[self.navigationController popViewControllerAnimated:YES];
it will get back to previous page ..
You can do as BoltClock had said.
and you can also set this title
go to the class where you have defined your navigation controller
and then go to the xib file..
in that in your navigation controller there is a option of navigation item select that
now go to attribute inspector and write down the title you wish to use
best of luck
Related
I am using a Tabbarcontroller in my application. I have added a tabbarcontroller as a root view to deleagate, also there are 5 tabs in it. Now the problem come I have added a logout button on delegate window it show on top of all view to the right hand side of navigation bar.
I used a logout button so that user can logout from any tabs and go back to the first tab of tabBar controller but it doesn't happen to me. Can any one suggest me how to do.
Try this
[yourTabBarController setSelectedIndex:0]
or
[tabBar setSelectedItem:[tabBar.items objectAtIndex:0]];
You can set the selectedViewController property of your UITabBarController. The documentation says:
"you can use this property to select any of the view controllers in the
viewControllers property"
You could, for example, create a category on UITabBarController with a method such as:
- (void)selectFirstController {
self.selectedViewController = [self.viewControllers objectAtIndex:0];
}
I'm having an annoying problem which takes the best off me :<
I've got 3 view controllers, one to show an advertisement in detail which also has a toolbar. Now what I want is, if the user presses the facebook icon on my toolbar in the first view it has to perform a check. If the check turns out false it needs to go to a 2nd view which shows a login screen. If the user logs in here it has to go to a 3rd screen which shows a simple input + button to update their status.
When the user is at this third screen there should be a button "Back", but this button shouldn't bring them back to View2 but it should bring them back to View1 (the advertisement detail screen).
I figured that I wanted to show the 2nd screen (if check turns false) without pushing it but keeping the NavigationBar + TabBar presented. I added some screenshots to clarify.
First view
Second view
I want this view to be presented without using PushViewController but keep the NavigationBar and TabBar.
Third View
I hope this is enough information, hopefully someone can help me.
Thanks in advance!
Perhaps the most natural thing to do here is to present the login view controller modally. When the user has logged in successfully, the first controller can then push the third view controller onto the navigation stack. This way, the back button will lead directly back to the first view controller, and the user will understand why.
So if we have three UIVIewControllers:
DetailViewController
FacebookLoginViewController
UpdateViewController
We have two viable options:
1) Upon successful login...pop the current LoginViewController and then push the UpdateViewController
PopViewController(detailViewController, false);
PushViewController(updateViewController, true);
2) Present the login Modally and simply present the UpdateViewController
PushModalViewController(loginViewController, true);
//ascertain result of login
if(IsLoggedIn) {
PushViewController(updateViewController, true);
}
consider the following view push logic.
if (!login) {
LoginViewController *lvc = [[[LoginViewController alloc] init] autorelease];
[self.navigationController pushViewController:lvc];
}
else {
ThirdViewController *tvc = [[[ThirdViewController alloc] init] autorelease];
[self.navigationController pushViewController:tvc];
}
It is : create and push the view controller when it is needed.
Try to pop the current view controller (without animation i guess) before pushing the new one. If there is only one view controller in the navigation stack no back button will be shown.
Haven't used Monotouch but i guess something like this:
this.NavigationController.PopViewControllerAnimated(false);
this.NavigationController.PushViewController(newViewController, true);
But as Caleb suggests it's probably better figure out a way that fits the normal navigation behaviours instead of hacking around it.
Here i developing simple application iphone. I need to create navigation bar with navigation back button in iphone. I'm using view controller page. I want to implement navigation controller. But i could not create back button in next page. I also created navigation bar.
In a 2nd sub view page code is
-(IBAction)settingspage
{
Settingscontroller *objec=[[Settingscontroller alloc]initWithNibName:#"Settingscontroller" bundle:nil];
navigationController=[[UINavigationController alloc] initWithRootViewController:objec];
[self presentModalViewController:navigationController animated:YES];
[objec release];
[navigationController release];
}
In the using this code it will create navigation bar in 3rd sub view. But i dont knw how to create navigation bar with back button in the 3rd sub view page. How to create navigation bar with back button in 3rd sub view using this code. Can anybody help me pls.
Back button will appear only in the view that was pushed to previously existing navigation bar using the method below:
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
If you will use that method and don't overwrite UIBarButtonItem *leftBarButtonItem then back button will be created automatically.
The whole application should use a single navigation controller. So you shouldn't be creating new controller's if you want to stack the views one above another. However you would need to create new navigation controller only when you need different flow type in the newly presented views. From your question i can infer you are creating new navigation controller's. Hence the solution would be to use the navigation controller already created in the subsequent view controller's.
It can be done by accessing the navigationcontroller as follows:
self.navigationcontroller
In my test project I have some 5 tabs on click of a tab it will go to that corresponding class, on click of back in that screen I will come back to my home page but with out the tab bar.. earlier what 5 tabs were there those are not coming ...
following code I am using under back button
where DataEntry is the class to where i need to navigate
- (void) back_Clicked:(id)sender
{
DataEntry *avController;
UINavigationController *addNavigationController;
if(avController == nil)
avController = [[DataEntry alloc] initWithTabBar];
if(addNavigationController == nil)
addNavigationController = [[UINavigationController alloc] initWithRootViewController:avController];
[self. navigationController presentModalViewController:addNavigationController animated:YES];
}
is I have to add that navigation controller to the tab view? how can I get the tab bar on click of back can any one help me ,thanx in advance
As I understand this, you must already be pushing this view controller either via navigation controller or modally. So the idea would be to simply dismiss it right?
If you have used [self.navigationController pushViewController:animated:] then just do [self.navigationController popViewControllerAnimated:YES]; . This should take you back to the earlier view controller.
If you have presented this modally like you have done here, you should do [self.navigationController dismissModalViewControllerAnimated:YES];.
If you need to return back from a view to the previous view using a back button inside a tab view , i would recommend using a navigation controller inside the view for each tab where you require this functionality. Trying to implement a custom back button without using the navigation controller, in my opinion, is only making things tough for yourself.
If you only want one view to be displayed when you tap on a tab bar button then an ordinary view controller inside the tab bar view should suffice.
The tab bar shouldnt be disappearing altogether unless its been implemented incorrectly.
Here's the setup:
I have a tab bar controller with two tabs. There is a navigation controller on top the second tab, so that I can view details from a table.
On tab #1, I have a button. When this button is pressed, it switches the selected tab over to tab #2.
My problem is this: Let's say I go to tab #2, then I select a line from my table to view the detailed information. Then, instead of hitting the "back" button to return to the base view, I select tab#1. Then I press my button. Tab#2 loads, but it is still showing the detailed view, instead of the table view that I want.
I know how to programmatically press the button.
[self.navigationController popViewControllerAnimated:YES];
But how would I do that when the button pressed method is inside the class for tab#1, which knows nothing of tab#2's navigation controller?
Hope that makes sense. Thanks in advance for any help!
Okay, I finally got it to work. The solution that was suggested gave me a good jumping off point. Here is the code that finally worked for me:
ARFinderAppDelegate appDelegate = (ARFinderAppDelegate)[[UIApplication sharedApplication] delegate];
[appDelegate.booksNavigationController popViewControllerAnimated:YES];
self.tabBarController.selectedIndex = 1;
I had to access the class that contained the NavigationController through an instance of my application delegate. I also had to remove the "objectAtIndex:1" because my application would crash.
Thanks for all the help, this has been a great learning experience for this iPhone development newbie!
use your delegate singleton.
[[delegate.tabBarController.viewControllers objectAtIndex:tab2Index] popViewControllerAnimated:YES];