I am looking to create a UINavigationController iPhone app with some UI that, as far as I can tell, is slightly strange. Despite my best efforts to figure out a good solution to this problem, I can't seem to find the right solution, so would appreciate some advice.
There will be a (customized) toolbar at the bottom with several buttons. When a button is pressed it will present a modal panel view, which slides up, closing other open panels, but leaving the toolbar visible. When the same toolbar button is pressed again the modal view slides down again. The modal views are used to choose a new UIViewController to push onto the UINavigationController. These modal slideup-panels can also be opened by buttons in the controllers that have been pushed onto the UINavigationController.
The main problem, as far as I see it, is presenting and dismissing the modal UIViewControllers so that the toolbar remains. Also - who does the presenting/dismissing? The App Delegate or the root ViewController, or someone else?
My initial (bad) solution was to have a root UIViewController that had a sub-UINavigationController whose view was used as a subview, and the toolbar & modal panels were just other subviews. But, for pre-iOS5 apps, sub-ViewControllers are bad and sick and wrong and evil (no matter how logical they seem).
Another (probably bad) option is to use a UINavigationController subclass as the root view controller, and have this handle all the toolbar functionality.
Any suggestions? Am I overlooking some obvious in-built functionality or a standard design concept?
Related
I have a UINavigationController which was created in Storyboards, and connected with push segues for each view controller. However, when I click "next" (which activates the push segue), then animation going forward is strange. (See: https://www.youtube.com/watch?v=0cFo9sUtBeM). Going back (Selecting the root controller of the UINavController in the UITabBarController) has the correct animation though. Any ideas why this could be?
Edit: the boxes in the video are added by me to protect client identity. The animation issue detailed is the slide animation which appears to come from the top right (or top left for the 'next' button).
It appears that setting a different Prompt for the navigation bar on the second view controller causes this weird animation effect. After removing the prompt, the animation now works as expected.
It looks like a navigation controller push and a modal transition. If I had to wager, I'd guess you have a modal transition hooked up to the button in storyboard, and code in the action method for the button doing a pushViewController:animated: on self.navigationController - (either that or the other way around, with a push hooked up in storyboard).
If that's the case, start by commenting out any button action code (any target/selector you setup in code, or any IBAction you setup in storyboard for that button).
I also recently had this problem using a Master Detail storyboard with an embedded Navigation Controller. The issue was fixed when I changed the Background of the View of the Detail screen from Default to a different color. I found it did not make any difference which color as long as it was not Default. I hope that this helps someone.
I have a rootViewController that is a UITabBarController. A UIToolBar is present in that controller since it has a SearchBar that is global to the app. In certain tabs, there should be specific UIBarButtonItems, or UISegmentedControl, along with the searchBar. In other tabs, there should be nothing in the toolBar, just a title.
What is a good way to lay out the view? Currently based on what tab is selected, the main toolBar from the rootViewController is either used as it is, have a UISegmentedControl added to it, hidden completely and replaced with another viewController that has its own toolbar, etc. To me, I'm thinking that each viewController that is present in its own tab can have its own ToolBar, and reference the global functionality, vs hiding/showing different toolbars.
sorry if this is a convoluted question. Just wondering if people had experience with this. Thanks.
The short answer is that there isn't really a good way to do this. If you're using a tab bar controller, the tab bar will always be visible along the bottom of your screen. Presumably each tab is a UINavigationController with a navigation bar at the top. There's not an appropriate place to put toolbar buttons in this layout.
A better design could be to abandon the UITabBarController and use a UINavigationController as your root view controller. Instead of tabs, you can have a table view with an item for each view of your application. Then you'll have room for a toolbar at the bottom of the screen. In fact, UINavigationController supports having a toolbar at the bottom. You just override the toolbarItems property to return the items that should appear in each of the child view controllers. You'll just need to set toolbarHidden to NO on the UINavigationController, and you're good to go.
I have a view (and corresponding view controller) in my iPhone app that allows the user to edit settings for the application. This view is accessible via a menu (a table view). I use pushViewController in my UIViewController subclass to get it shown. When I do this, it appears as I expect - the nav bar appears on top of the xib, and the empty space I left up there in the xib is occupied.
I also sometimes show that settings view as a modal view using presentModalViewController. When I do this, the top of the xib starts at the bottom of the nav bar instead of underneath it.
The documentation does say that presentModalViewController will resize the view to fit, so I could see this being expected behavior. However, for me, it isn't desired behavior.
I can kind of work around it by setting the settings view controller to not show the nav bar, but then there's a weird empty space at the top of the view.
Ideally, I'd like to use the same xib in both of these situations. However, maybe that's not a best practice? How do you guys usually reuse a xib?
I was thinking that maybe I could have the view controller shift all of the controllers up if it's in modal mode, but I'd like something better, if it's available.
Each UIView has an autoresizingMask property. By configuring that (can be done in Interface Builder), you should be able to reuse the view and have it automatically resize to take up the whole screen when the nav bar should not be there.
Apple's documentation is here:
http://developer.apple.com/iPhone/library/documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/WindowsandViews/WindowsandViews.html#//apple_ref/doc/uid/TP40007072-CH8-SW10
I am using a UINavigationController to handle the pushing and poping of viewControllers in my app. Theres a section where i have a tab bar (not using UITabbarController) which is manageed by the same UINavigationController, i simply add the UITabBar to the navigation controllers view (by using addSubview).
The Problem:
I have some UIViewControllers with table views being pushed into the navigation stack, since my Tab Bar is part of the view and not the navigation stack the TableViews are cut off at the buttom because the Navigation Controller does not know of the tab bar because its in its view and n ot the navigation stack. Without a navigation controller i would just resize the ViewControllers view and it would work fine, but when i try to do that it seems like the NavigationCOntroller just ignores my frame and sets its own and therefore the table views are cut off. I found one solution which was to add some extra cells and hide them and that works sort of OK but its kind of hackerish, anyone have any suggestion of how to go about this in a different non -hackerish way?
Thanks
Alright, so i solved the problem. I had tried resizing the UITableView instead of the viewController before, but this did not work. I just realized though, that this did not work because i was using a UITableViewController which manages its own tableView and was not letting me change the frame of it (maybe i was changing it in the wrong place, tried in viewDidLoad, i bet if i did it after the call to [super viewDidload] it would have worked..o well). So I changed the class to a UIViewController and managed the table view in there, now it works good, thanks for the replies.
Try making the root view a UIView with a UITableView for a subview. Then add the UITabBar to the UIView instance. Now the UITableView won't know about the UINavigationController.
I have been in the process of learning to build iPhone applications for the last two weeks. I've gotten through a fair amount of content, and now I'm trying to create a modal pop up with presentModalView.
I can can successfully create and slide up a view, but I notice that modal views don't provide you with a default navigation bar at the top of the window, which makes sense for flexibility I guess. Most modal views I've seen have a "Cancel" and a "Done" or "Save" button as navigationItems on what looks to be a UINavigationController. My thought then was just to instantiate a navigation controller and push the single view onto the view controller stack, and presentModalView:navController.view ...
Because the view is relatively complex, I was trying to lay out both the UINavigationController, with the bar buttons, and the view I was hoping to push onto the stack in a single xib -- no matter what I try, I can't seem to get the linkages correct. Can you even do this? Or should I create a separate class/xib for the view I'm going to be pushing onto the navigation controller? Seems like a lot of classes and files for one screen, so my feeling is I must be missing something.
At this point, I could have done it programmatically about an hour and a half ago... however, this is a real nag, since IB seems GREAT for some things. Anyone have an experience with a situation like this?
Thanks,
Josh
If you're not going to use this new XIB for navigation, there's no point in making a navigation controller.
In interface builder, simply drag a UINavigationBar to the top of your view, and add a "Done" Button. Now, add an IBAction to the done button to dismiss the view controller. Your ViewController code for the dismiss IBAction should look something like this:
-(IBAction)dismiss {
//Any logic before dismissing the modal view
[super dismissModalViewControllerAnimated:YES];
}