how to use toolbar to connect two view controller - iphone

have two view controller(FirstViewController,sixViewController),i create a toolbar button in the navigation bar using interface builder,when i press the toolbar button it should direct me to sixViewcontroller,in the sixViewcontroller i have back button to return firstviewController with slide in animation,my toolbar name is Item.help need guys coz I'm still new for iOS.
UIViewController *viewController6 = [[sixViewController alloc]initWithNibName:#"FourthViewController" bundle:nil];
UIViewController *viewController5 = [[FifthViewController alloc]initWithNibName:#"FifthViewController" bundle:nil];

Sounds like you would be much better off using a NavigationController which handles placing the navigation bar and managing the viewController stack automatically.
The UINavigationController class reference is a good place to start
http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html

Related

Navigation Controller - How to Add in Another View Controller in Xcode?

I'm relatively new to iOS programming but I'm learning bit by bit. I've got two nib files, one is my HomeViewController and the other is called 'ReceiptTableViewController'. The HomeVC should not have a top nav bar but the ReceiptTableVC should, with a title and 'back' where the user can swipe to go back to HomeVC.
How would I go about adding this? I've dragged the Navigation Controller to the side of my ReceiptTableVC in the nib file.
I've searched for various answers but some contradict each other as the authors use different versions of Xcode, and some start with storyboards, etc.
Any help is much appreciated!
I haven't used storyboard
You can use this method to decide whether your navigationBar show or not in your viewController.[self.navigationController setNavigationBarHidden: animated:];
In your AppDelegate:
UINavigationController *naviController = [[UINavigationController alloc] initWithRootViewController:homeController];
naviController.navigationBarHidden = YES; //set home controller navigation bar hidden.
self.window.rootViewController = naviController;
Then in your ReceiptTableViewController's viewDidLoad method:
[self.navigationController setNavigationBarHidden:NO animated:NO]; // show the navigation bar.
This is how to declare a UINavigationController programmatically. You can have a try.

Pushing Tabbarcontroller from a UIViewController

i`m wondering if its possible to push a TabbarController from UIViewController ?
what i want to do is:
when the user opens the app it shows a View with two buttons to select the language he want, this view does not contain anything except the two buttons, no tab bar, no navigation bar.
after selecting the preferred language it should push a tab bar view with 5 tabs in it. each tab contain a tableview controller.
is it possible ? if yes please explain how to do it i`m little bit new for this :)
thank you in advance :)
Well you can add it as subview to UIWindow of your app delegate. You have to make a property UIWindow of your AppDelegate class.
Now When in your UIViewController button is pressed, do something like this:
- (void) buttonPressed:(id)sender{
AppDelegate *delegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
UITabBarController *tab = [UITabBarController youWayOfInitializingIt];
[delegate.window addSubview: tab.view];
}
Sure, just present an UITabBarController from the UIViewController using presentModalViewController.
I would try dragging out two different tab bar view controllers, one for each of your languages. Ctrl-drag each button on your UIViewController to its respective language's tab bar view controller and choose the type of transition you want. However, if you want to use the push transition I suggest embedding the original UIViewController in a navigation controller. You can do this by clicking on the UIViewController and then...
Editor --> Embed in ---> Navigation Controller
This will provide you with a navigation bar and a back button if the user wants to go back and change the language.

How to add a TableView with NavigationBar (Navigation Controller) to a View

I got a tabbed application like this:
and already set up everything like it should look, but it won't function yet. I already googled my problem and they said you first need to set up a NavigationController with the table view as rootView and then the NavigationBar but I really couldn't figure it out. Hope someone of you can help me.
Based on your response to my comment on your question here is what you should be doing:
First off, in order to make it look like the settings app table, you will need to change the style of your UITableView to UITableViewStyleGrouped.
Your hierarchy will consist of the following:
The viewcontroller that is actually added into your UITabBarController viewControllers array(since I see you have a tabbar as your lowest level of navigation) should be an UINavigationController. The root viewcontroller of the navigation controller should be the uiviewcontroller subclass you made that contains your table view. (let's say it's called SettingsViewController)
SettingsViewController *settingsViewController = [[SettingsViewController alloc] init];
UINavigationController *settingsNavController = [[UINavigationController alloc] initWithRootViewController:settingsViewController];
You will probably need to create a different UIViewController subclass for each type of detail pane you're going to want (if they have different functionality).
In the didSelectRowAtIndexPath UITableViewDelegate function, you will create the appropriate detail viewcontroller and push it onto your navigation stack.
Let's say you have a volume settings view controller as an example. The following is the code you would have in the function I just mentioned. Keep in mind you also need to actually check the index and/or section of the selected row to figure out which detail view should be shown.
VolumeSettingsViewController *volumeSettings = [[VolumeSettingsViewController alloc] init];
[self.navigationController pushViewController:volumeSettings animated:YES];
By default, this will function pretty much like the Apple Settings app navigation. The navigation bar will automatically have a "back" button to take you back to the settings view.
If you are using a Storyboard, select your view controller, go to the "Edit" menu and choose, "Embed in Navigation Controller."
If not using story boards, assuming this will be done in code, you need to create things in a reverse order of their hierarchy - something like this:
Create an instance of the Einstellungen tab's TableViewController using initWithNibName:
Create a UINavigationController using initWithRootViewController: and setting the Einstellungen as the root
Create a UITabBarController and set your navigation controller as one of the view controllers of this tab bar controller
Add the tab bar controller as a subview to the main window in your application delegate
This will create this hierarchy:
Tab bar controller
->view controller: Navigation Controller -> root view controller: Einstellungen

Navigation Issue with UITableView

How do I navigate back to the previous page with a UITableViewController. I tried to show a navigation bar with navigation button at the top of the screen, but the navigation bar will not show. I know that you have to give the previous view a title but when I go to do that it does not show anything. Also, since it is a UITableViewController I am not able to drop a navigation bar and add a button to the main view. All I would like to do is display my lists and have the option to navigate back to the previous list with a single button in the upper left corner.
The problem you having with the NavigationController is that your tableViewController is not in the NavigationController hierarchy. Want you want to do this when adding the tableViewController:
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:yourTableViewController];
Then you can do this to add yourTableViewController:
[self.view addSubview:navigationController.view];
If you don't want the navigationBar to appear on the tableViewController just use:
self.navigationController.navigationBarHidden = YES;
in yourTableViewController viewWillAppear method.
When your going to add the view after the tableView you just use:
[self.navigationController pushViewController:someViewController animated:YES];
It's not enough to give the child view a title. You need to give the child view's navigation item a title before you present it. For example, in the parent view, before you push the the view to the navigation stack, do something like this...
[MyChildView.MyNavigationItem setTitle:#"A cool Title"];
For the navigation you are trying to achieve you should be using a UINavigationController. It already has the functionality you describe with the navigation bar and back button built into it.
To move to the next screen (which can be a UITableViewController) you use pushViewController:animated: and to move to the previous screen you use popViewControllerAnimated: (although the built in back button will do this for you).
I suggest reading the UINavigationController class documentation if you are not already familiar with it.

Set a navigation controller without an app delegate

I would like to show a Navigation Controller after clicking a button. Every tutorial assumes the navigation controller will be the first screen so it links it to the App Delegate, but App delegate only appears at MainWindow.xib.
How do you guys add a navigation controller to a view different than the MainWindow?
Thanks!
Here is some sample code to expand on Roger's answer. The following method is linked to some user interaction on the current view controller (to compose an email for example). This will give the compose view the navigation bar across the top instead of coding buttons inside your custom view.
-(void) composeButtonPushed: (id) sender {
ComposeViewController *controller = [[ComposeViewController alloc] initWithNibName:#"ComposeView" bundle:nil];
UINavigationController *composeNavController = [[UINavigationController alloc] initWithRootViewController:controller];
[self presentModalViewController:composeNavController animated:NO];
}
UINavigationController is to navigate a heirarchy of views with UIViewControllers. If you don't have a root UIViewController, it won't work (and doesn;t make sense). If you do have a UIViewController, you simply send a - (id)initWithRootViewController:(UIViewController *)rootViewController init message to a new navigation controller passing in your UIViewController.