Using splitviewcontroller with storyboards? - ios

I have created a splitview controller in a storyboard that has a navigation bar across the top. I also have a master view with a tableview that when selected displays the correct view in the detail view controller.
How can I update the splitview controller's navigation bar title? I know I can access the master's nav bar through "self.navigationItem.rightBarButtonItem" but how do I access the main nav bar from this file?
Thanks

If you have a navigation bar across the top, then you can set the title like this:
self.title = #"this is my title";
If your title is fixed and doesn't change, then just add that line in your viewDidLoad method or where ever you would setup items in your view.
If you are trying to set the title programmatically, then it depends on which view controller you are in when you try to set the title. In the example above, it will set it for the view controller you are in.
If you want to set the opposite view controller navigation bar, you have a couple of ways to choose from depending on when you want to update it.
Generally though you would reference the opposite view controller directly using a delegate or indirectly using the splitViewController.viewControllers array.
it sounds like you already have a reference to the detail view controller. If so and you want to change its title from the master you can do so like this:
[self.detailViewController setTitle:#"New Title"];
hope that helps,
be well

Related

Segue-ing to Embedded view controller

I have have a view controller that is embedded in a UINavigationController and I want to segue to another view controller that is also embedded in a different UINavigationController. If I try to use a push segue, I get an error saying that I can't push a UINavigationController. However, I don't think using a modal segue is appropriate. How should I go about this?
How should I go about this?
You should use a single navigation controller.
the problem is that I want different bar button items for each view controller and they won't change
Each view controller can set up the bar buttons however it likes. Take a look at UINavigationItem. Each view controller has a navigation item, and the navigation item has various properties such as leftBarButtonItems and rightBarButtonItems that you can use to set the buttons.

which method be called-back when switching between tab bar view?

My initial question is:
I want to change the navigation item (both title and button when switching between tabs).
I tried the answer : Storyboard navigation controller and tab bar controller. It says:
self.parentViewController.navigationItem setTitle:#"Title"];
add to viewDidLoad in each view controller works.
However, when I re-enter the view, the tile won't change. I think it means viewDidLoad won't get called-back when re-entering.
Any solution about Storyboard navigation controller and tab bar controller ?
You're looking for viewWillAppear:. Here's Apple's documentation. This method will be called on the controller that is being presented, or being transitioned to. viewWillDisappear: (documentation here) is called on the controller that is being transitioned away from.
It would be better to have a navigation controller for each tab in you tab bar. Then you can set your titles right in the storyboard.

Using UITableViewController in a navigation bar

I'm new to iOS, but I know the basis. I want to host 3 UITableViewController in a UITabBarController using the storyboard.
I dragged a UITableViewController from the object list(?) and control dragged creating a seguel. Now the tab shows successfully the table view controller.
The issue is the rows are taking the space of the status bar. So I want a navigation bar(?) there, with a title. Since I'm new to iOS I don't know the following:
Given the fact that UITabBarController is the first controller ever, the hosted UITableViewController should not have a back button, obviously. So is it correct to use a navigation bar to display a title (and possible add/edit buttons)
If so, I tried dragging the Navigation Bar but it doesn't work.
What am I missing or doing wrong?
hope this helps
actually it is done for another answer. but it will be handy to u too
You will want to add in 3 UINavigationControllers. Have each tab in the tab bar controller segue to a different navigation controller. Then set the root view controller for each navigation controller to one of the table view controllers.

Navigation title not showing on view with tab view controller, but "back" navigation works

I'm relatively new to iOS Objective-C development, and I've come across a problem that I can't find a solution to.
I have a Table View Controller, with two prototype cells on it, which populate fine. This Table View Controller is one of three Tab Views, and the View that sends to the Tab Views has a Navigation Controller. This means that the views within the Tab Views also have a Navigation bar. The bar works fine, in terms of the "back" button working as expected, and the bar being in position. However, (at least on the List View) the Navigation Bar isn't fully recognised - it's title doesn't appear, and the table cells start directly below the status bar, rather than below the navigation bar.
Here's a couple of screenshots showing the problem:
what appears in Xcode (what I expect to happen)
And then on the device, this is what actually appears - the Back button in place and working fine, but no title field, and the table cells start too high.
I've tried adding Navigation Bar's and Navigation Items, and while adding a Navigation Item allows me to put a title on in Xcode, it still doesn't appear on the device in testing. I also tried to add another Navigation Controller just before this view, but that didn't resolve the issue either, and it caused navigation problems further down in the heirachy.
Hope I've been clear enough, please say if I need to post more information - I'm relatively new to Xcode and so not sure what exactly is applicable and what isn't. Thanks!
please try this code, it might fix your table position
// Since in iOS7 the nav bar is translucent by default, so the table view starts at (0,0)
// you can either disable the translucent, which i don't recommend unless you really want to
// or just add 64 pixel on the top of your table view
[self.YOURTABLEVIEW setContentInset:UIEdgeInsetsMake(64, 0, 0, 0)];
and for the title, please try this
self.tabBarController.navigationItem.title =#"YOUT TITLE NAME";
Hope that helps..
Assuming your hierarchy as
NavigationController -> ViewController -> TabBarController -> ViewController1
-> ViewController2
-> ViewController3
If you want to hide navigation item in viewcontroller1, Add the following line
self.navigationController.navigationBarHidden = YES;
If you want to show title in viewcontroller2, Add the following line in
self.navigationController.navigationBarHidden = NO; //add this if you hide navItem viewcontroller1
[self.parentViewController.navigationItem setTitle:#"Title"];
If you want to hide backbutton and show title in viewcontroller3, Add the following line
self.navigationController.navigationBarHidden = NO;
[self.parentViewController.navigationItem setTitle:#"Contacts"];
self.parentViewController.navigationItem.hidesBackButton=YES;
Add this lines to viewdidAppear method instead of ViewdidLoad ,if you have problems inshowing when switching tabs.
I had the same problem, but what I did to create this problem was that my buttons action was connecting to the actual table itself and not the table Controller. I removed the modal action and created a new action to the table controller and it fixed the problem.
Try to click the Navigation Bar from your storyboard or nib.
Then add your title to the property.

Using UINavigationController view

I would like to better understand the use of UINavigationController's.
I have setup a new project with a UINavigationViewController, as well as two other view controllers.
In my app delegate I have the following:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
firstViewController = [[NCTFirstViewController alloc] initWithNibName:#"NCTFirstViewController" bundle:nil];
navController = [[NCTNavViewController alloc] initWithRootViewController:firstViewController];
self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];
Within my UINavigationController.m file I can set the title and set up buttons, but this does not work.
This only works if I setup the self.navigtionController items in the actual View Controller itself. Is this correct, or is there something I should be doing in the UINavigationController to get this to work.
Ideally I am looking for a UINavigationController that handles all the pushing to other controllers. In the long run it would be used as a menu system. So if the user clicks a button at the top, they are pushed to a new View Controller but without the back option, simply the same menu items in the navigation bar at the top, which shows a new center view controller.
The issue I am having is understanding how this is setup. If I have to setup this in the view controllers itself, would they all not duplicate the same code. Of course I could setup all the 'movement' in the AppDelegate, but this doesn't seem correct and would pack up the App Delegate itself.
If you look at the UINavigationController class reference, it says (emphasis added by me, but you should read it all so that you understand how this works):
Updating the Navigation Bar
When the user changes the top-level view
controller, whether by pushing or popping a view controller or
changing the contents of the navigation stack directly, the navigation
controller updates the navigation bar accordingly. Specifically, the
navigation controller updates the bar button items displayed in each
of the three navigation bar positions: left, middle, and right. Bar
button items are instances of the UIBarButtonItem class. You can
create items with custom content or create standard system items
depending on your needs. For more information about how to create bar
button items, see UIBarButtonItem Class Reference.
The bar button item on the left side of the navigation bar allows for
navigation back to the previous view controller on the navigation
stack. The navigation controller updates the left side of the
navigation bar as follows:
If the new top-level view controller has a custom left bar button
item, that item is displayed. To specify a custom left bar button
item, set the leftBarButtonItem property of the view controller’s
navigation item.
If the top-level view controller does not have a
custom left bar button item, but the navigation item of the previous
view controller has a valid item in its backBarButtonItem property,
the navigation bar displays that item.
If a custom bar button item is
not specified by either of the view controllers, a default back button
is used and its title is set to the value of the title property of the
previous view controller—that is, the view controller one level down
on the stack. (If there is only one view controller on the navigation
stack, no back button is displayed.)
The navigation controller updates
the middle of the navigation bar as follows:
If the new top-level view controller has a custom title view, the
navigation bar displays that view in place of the default title view.
To specify a custom title view, set the titleView property of the view
controller’s navigation item.
If no custom title view is set, the
navigation bar displays a label containing the view controller’s
default title. The string for this label is usually obtained from the
title property of the view controller itself. If you want to display a
different title than the one associated with the view controller, set
the title property of the view controller’s navigation item instead.
The navigation controller updates the right side of the navigation bar
as follows:
If the new top-level view controller has a custom right bar button
item, that item is displayed. To specify a custom right bar button
item, set the rightBarButtonItem property of the view controller’s
navigation item.
If no custom right bar button item is specified, the
navigation bar displays nothing on the right side of the bar.
The
navigation controller updates the navigation bar each time the top
view controller changes. Thus, these changes occur each time a view
controller is pushed onto the stack or popped from it. When you
animate a push or pop operation, the navigation controller similarly
animates the change in navigation bar content.
So, to do what you want, you do need to set the title and buttons in each view controller. The easiest way to set the title is to set it in the storyboard/xib, or in code when you create it.
You should also replace the root view controller instead of pushing the view controller onto the navigation stack so that you don't keep adding view controllers to the stack. This also avoids displaying the back button, and you won't need to explicitly get rid of it. You would do this by using the setViewControllers:animated: method like this:
[self.navigationController setViewControllers:[NSArray arrayWithObject:theNewViewController] animated:YES];
There is only one NavigationController and this NavigationController controls all the ViewControllers. So barButtonItems and titles are set in each ViewController, you should not set them directly to a NavigationController.
If you want to push a new ViewController and won't push back, I think this may cause some problem because the NavigationController is using a Stack to handle all the ViewControllers. Seems that you will push a ViewController in the stack but not pop it, and maybe you will get some behavior you don't want.
If you still want to implement this, I think you cannot avoid do similar setting in different ViewControllers.

Resources