ios5 storyboard add right button to nav bar - ios5

So i started to experiment with storyboard.
so my storyboard is as follow
nav controller -> tableviewcontroller -> tabBarController -> tableViewController as an item of the tab bar (buy linking them through relationship segue)
The last tableviewcontroller does appear with a navbar on top but i can't add any bar button item on it. even the code self.navigationItem.rightBarButtonItem = self.editButtonItem does not make it appear.
The thing is with the first tableviewcontroller it does work (code and designer works). I suspect it had to do something with the first nav controller.
I did try embedded in the nav controller in the tableviewcontroller but that just shoes 2 navbar.
Any help is appreciated
Thanks,
EDIT: Add storyboard screenshot

Based on my own experience, you typically use this sequence:
tabBarController -> navController -> tableViewController
In other words, a tab bar controller with a tab bar item containing a navigation controller, which in turn holds a table. If this isn't the solution you're looking for or the button doesn't show up, could you include a snapshot of your storyboard?
UPDATED:
If you are attempting to make your tab bar dynamic, you need to change the array that tabBarController.viewControllers is using. As mentioned in the comments, this isn't the best approach if you are following the interface guidelines but here's how I got it to work:
//Initial tab bar items
self.tabBarController.viewControllers =
[NSMutableArray arrayWithObjects:originalItem1, originalItem2, nil];
//Now let's replace the old items with some new ones!
self.tabBarController.viewControllers =
[NSMutableArray arrayWithObjects: replacementItem1, replacementItem2, replacementItem3, nil];
As you can see, we initially set the tab bar to contain two tab bar items (originalItem1 & 2). Then the next bit of code replaces those items with some new ones (replacementItem1 & 2 & 3). Since it appears you are trying to change the tab based on the view the app is currently in, you would probably want to include this in the viewWillLoad method. This means that the tab bar should update as the view is about to be loaded. Of course, you would need to set some conditions in nearly every view so that the tab bar would constantly be changing to the one you want.
Unfortunately, this is more of a programmatic approach and you are using storyboard. I don't see an obvious way of getting this done in the storyboard alone, but the code should be able to help.

Related

Trying to add an Edit button to the navigation bar

I had created a xcode project of single view application. I put a tableview and navigation item on my storyboard screen. Now, I bind the array data source to tableview and set the code as below to show edit button on the navigation button.
self.navigationItem.leftBarButtonItem = self.editButtonItem;
However, it seems can't working. I can't find any button on my navigation bar.
Someone can tell me how to make the edit button show?
Thanks!
I put a tableview and navigation item on my storyboard screen.
It sounds like maybe that's the problem. The way to set this up is to start with a UINavigationController as your storyboard's initial controller, and put the UITableViewController in a relation segue from that (as the navigation controller's root view controller). Now if the table view controller says
self.navigationItem.leftBarButtonItem = self.editButtonItem;
the edit button will appear in the navigation bar.
To see an example, start with the Master-Detail template (for iPhone). The Master view controller is structured in the way I'm describing.

Storyboard: Views with navigation controller before tabbar

I have a little problem related to implementing a tabbar with navigationcontrollers, when I have two views before the tabbarcontroller, which also uses a navigationcontroller.
This is my setup in StoryBoard
http://i.stack.imgur.com/8P4Zw.png
http://i.stack.imgur.com/ei3xa.png
But this is not working as I want, because I get two navigationbars (Picture number 2) when I enter the tabbar screen. I know I just can delete the navigation controllers in the tabbar or change the segue to modal, but if I do so, I would not have the ability to add individuel UIBarbuttons to each tabbar view or set individuel navigationbar titles. I would also like to use the push segue through out the app, as it is a kind of an "step by step" app. My question is: How I can eliminate the double navigationbar, when I enter the tabbar, but still have the ability to set a title for each view related to the tab and continue to use the push segue and a navigationcontroller?
I hope you understand my question.
You -can- set individual buttons for each view controller. Grab a tab bar item and drag it to the navigation bar of whichever view controller you want. You can also set the individual title of each view controller. Like you said, there is no reason for the 2nd and 3rd navigation controller you added right after the tab bar controller.
You can set buttons both in the Storyboard and programmatically and they can be different at different stages of your view controller. You should thus delete the second and third navigation controllers and either drag and drop the buttons you want where you need them, and/or deal with it programmatically if necessary.
One example of what you could do programmatically:
UIBarButtonItem *yourButton = [[UIBarButtonItem alloc] initWithTitle:#"yourTitle" style:UIBarButtonItemStylePlain target:self action:#selector(yourSelector)];
self.navigationItem.leftBarButtonItem = buttonSegueBackToAccueil;
This creates a UIBarButtonItem for the controller you are in and places it as the left button of the navigation controller bar. It will run the method "yourSelector" when clicked.

UINavigationBar unresponsive after canceling a UITableView search in nav controller in tab bar in a popover

Ok, this is an odd one and I can reproduce it with a new project easily.
Here is the setup:
I have a UISplitViewController. In the left side I have a UITabBarController. In this tab bar controller I have two UINavigationControllers. In the navigation controllers I have UITableViewControllers. These table views have search bars on them.
Ok, what happens with this setup is that if I'm in portrait mode and bring up this view in the popover and I start a search in one of the table views and cancel it, the navigation bar becomes unresponsive. That is, the "back" button as well as the right side button cannot be clicked.
If I do the exact same thing in landscape mode so we are not in a popover, this doesn't happen. The navigation bar stays responsive.
So, the problem only seems to happen inside a popover.
I've also noticed that if I do the search but click on an item in the search results which ends up loading something into the "detail view" of the split view and dismissing the popover, and then come back to the popover and then click the Cancel button for the search, the navigation bar is responsive.
My application is a universal app and uses the same tab bar controller in the iPhone interface and it works there without this issue.
As I mentioned above, I can easily reproduce this with a new project. Here are the steps if you want to try it out yourself:
start new project - split view
create new UITableViewController class (i named TableViewController)
uncomment out the viewDidLoad method as well as the rightBarButtonItem line in viewDidLoad (so we will have an Edit button in the navigation bar)
enter any values you want to return from numberOfSectioinsInTableView and numberOfRowsInSection methods
open MainWindow.xib and do the following:
please note that you will need to be viewing the xib in the middle "view mode" so you can expand the contents of the items
drag a Tab Bar Controller into the xib to replace the Navigation Controller item
drag a Navigation Controller into the xib as another item under the Tab Bar Controller
delete the other two view controllers that are under the Tab Bar Controller (so, now our tab bar has just the one navigation controller on it)
inside the navigation controller, drag in a Table View Controller and use it to replace the View Controller (Root View Controller)
change the class of the new Table View Controller to the class created above (TableViewController for me)
double-click on the Table View under the new Table View Controller to open it up (will be displayed in the tab bar inside the split view controller)
drag a "Search Bar and Search Display" onto the table view
save the xib
run the project in simulator
while in portrait mode, click on the Root List button to bring up popover
notice the Edit button is clickable
click in the Search box - we go into search mode
click the Cancel button to exit search mode
notice the Edit button no longer works
So, can anyone help me figure out why this is happening?
Thanks,
Mark
Ok, got an answer from Apple Developer Technical Support. They investigated it and found it is a bug in the UIPopoverController. He gave me a workaround that kind of works but the right button in the nav bar ends up sliding across the screen after canceling the search. But, at least it fixes the issue. He also suggested I send in a bug report to Apple and I've done that as well. Hopefully they will fix this in the next version of the SDK.
Here's a copy of the relevant portion of the Apple engineer's response:
I've created my own project and dipped into what is going on and it looks like it's a bug in the UIPopoverController where after the UISearchBar is being dismissed, something is being obstructed in the navigation bar.
There's a workaround that I've found for now, though the animation that occurs is not amazingly optimal:
- Use the – searchBarCancelButtonClicked: method of UISearchBarDelegate and add the following:
self.navigationItem.rightBarButtonItem = nil;
self.navigationItem.rightBarButtonItem = self.editButtonItem;
As I said, it looks like the popover is pushing the button onto the navigation bar, so it may not be what you're looking for.
I tried the rightBarItem technique mentioned, but it didn't work for me. I had to do this (which is also a hack really)
[self.navigationController setNavigationBarHidden:YES animated:NO];
[self.navigationController setNavigationBarHidden:NO animated:NO];
This might be because my UINavigationBar isn't one unified with the popover, but I can't say for sure.

Tab Bar within a navigation based aplication (Again)

Here is my problem:
I've read a lot about how to use a tab bar within a navigation based application, but i still can't figure it out. I have tried both to use and avoid using a tab bar controller, but i just can't find the solution.
I already have a navigation based app working. I have several nib files (views), each one with its own view controller, that i programmatically push onto the navigation controller stack. I need one of this views to have a tab bar that allows me to switch between some of the others. I understand how the tab bar works, and i do think what i need is to use a tab bar controller, since it would allow me to define the view controllers associated with each tab bar item, and manage all about them. However, i can't see how to do it.
If i do declare a tab bar controller in my "tabBarViewController", draw the tab bar controller in my "tabBarView" and link them with the IB, it will give me an error (I reckon this is because i haven't really pushed the tab bar controller's view? do i need something equivalent to "[window addSubView:[tabbarcontroller view]]?). In this case, all i need to know is how to "see" the tab bar controller's top view controller's view within a view controller i have already pushed.
If i try not to use a tab bar controller, as i have read is the best solution to this problem, ¿how do i manage tab bar items, the switchs between them, etc?
I would really appreciate your help.
You can't push a tab bar controller onto a navigation controller stack. There's just no supported way to do it.
What you may want to consider instead is creating your own instance of UITabBar, then using a delegate that conforms to UITabBarDelegate. That way, your delegate will receive the tabBar:didSelectItem: message whenever a tab bar item is selected by the user. You'll have to manage the NSArray of items for the bar yourself, though, without using IB.
Once you've got that figured out, all that's left to do is push a regular UIViewController onto your navigation stack like any other, and just have that controller manage your tab bar and delegate.
I just made an App with a tabBar controller and 5 navControllers. All you need to do is load the nibs and navigation controller inside the first element of the tabBar controller. You can HIDE the tabBar even if the views are inside it, and make it appear in the view you need it to.
You can do this with a bit of code, like so:
FooViewController *foo = [[FooViewController alloc] init];
BarViewController *bar = [[BarViewController alloc] init];
UITabBarController *tabby = [[UITabBarController alloc] init];
[tabby setViewControllers:[NSArray arrayWithObjects:foo, bar, nil] animated:NO];
[self.navigationController pushViewController:tabby animated:YES];
[foo release];
[bar release];
[tabby release];
You could probably do it with IB as well, just load the tab bar controller from a nib.
I built a sample project that demonstrates this in action, you can download it from http://s3.thismoment.com/navtab.zip

Toolbar items in sub-nib

This question has probably been asked before, but my google-fu must be inferior to everybody else's, cause I can't figure this out.
I'm playing around with the iPhone SDK, and I'm building a concept app I've been thinking about. If we have a look at the skeleton generated with a navigation based app, the MainWindow.xib contains a navigation controller, and within that a root-view controller (and a navigation bar and toolbar if you play around with it a little). The root-view controller has the RootViewController-nib associated with it, which loads the table-view.
So far so good. To add content to the tool bar and to the navigation bar, I'm supposed to add those to in the hierarchy below the Root View Controller (which works, no problem). However, what I can't figure out is, this is all still within the MainWindow.xib (or, at runtime, nib). How would I define a xib in order for it to pick up tool bar items from that?
I want to do (the equivalent of, just reusing the name here)
RootViewController *controller = [[RootViewController alloc] initWithNibName:nil bundle:nil];
[self.navigationController pushViewController:controller animated:YES];
[controller release];
and have the navigation controller pick-up on the tool bar items defined in that nib. The logical place to put it would be in the hierarchy under File's Owner (which is of type RootViewController), but it doesn't appear to be possible.
Currently, I'm assigning these (navigationItem and toolbarItems) manually in the viewDidLoad method, or define them in the MainWindow.xib directly to be loaded when the app initializes.
Any ideas?
Edit
I guess I'll try to explain with a picture. This is the Interface Builder of the main window, pretty much as it comes out of the wizard to create a navigation based project. I've added a toolbar item for clarity though. You can see the navigation controller, with a toolbar and a navigation bar, and the root view controller.
IB Screenshot http://img526.imageshack.us/img526/3507/rootviewcontroller.png
Basically, the Root View Controller has a bar button item and a navigation item as you can see. The thing is, it's also got a nib associated with it, which, when loaded will instantiate a view, and assign it to the view outlet of the controller (which in that nib is File's Owner, of type RootViewController, as should be).
How can I get the toolbar item, and the navigation item, into the other nib, the RootViewController.nib so I can remove them here. The RootViewController.nib adds everything else to the Root View Controller, why not these items?
The background for this is that I want to simply instantiate RootViewController, initialize it with its own nib (i.e. initWithNibName:nil shown above), and push it onto the navigation controller, without having to add the navigation/toolbar items in coding (as I do it now).
First off, the way you've worded your question is a bit confusing here, but I think I understand.
You've got a couple options here. If you want to design your toolbar, just add one to the view you are loading and drag the various buttons and separators onto it in Interface Builder. Then create IBActions in that view's view controller and drag connections from your toolbar items to the various actions. Since you are using a Navigation controller, though, you will want to hide the toolbar you get by default by unchecking the "Shows Toolbar" box in your MainWindow.xib when the UINavigationController is selected (Attributes tab in the IB inspector).
alt text http://cimgf.com/files/toolbarthing.png
Alternatively, you can just add toolbar items programmatically in the viewDidLoad method by calling [self setToolbarItems:items]; where items is an NSArray of toolbar items.
Really there is no way that I'm aware of to cause the navigation controller to use your custom toolbar. Just hide the main one and use your custom one.