How to add a subview to a UINavigation Controller without losing navigation bar? - ios

I have a SplitViewController which has two UITableViewControllers - one master/root one detail. Everything works swimmingly.
I have a UIView which is shown on the detail view controller before the user selects an item in the root view controller. It's set up like this:
[self.navigationController.view addSubview:makeSentenceHelperView];
[self.navigationController.view bringSubviewToFront:makeSentenceHelperView];
The detailViewController is set up like so:
UINavigationController *detailNav = [[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];
Where detailViewController is a subclass of UITableView.
The problem is that this subView hides the buttons and navigation bar from the detail view controller's navigation bar - which is a problem when you launch the SVC in portrait mode (there's no way to select a root item with the root popup).
How can I present the view inside the navigation controller, so that the navigation bar and buttons appear in the detail view?

Don't make detailViewController a subclass of UIView, instead go with UIViewController. So your splitView array will contain a instance of UINavigationController(rootVC) and other of UIViewController (detailVC).
Add a toolbar on the top of detailViewController and in landscape mode left side will be covered by your UITableView of rootVC and you will be able to see toolbar where you can add some button to its right side (will probably serve as navigation bar..:) . Rest of the things can be handled by UISplitViewControllerDelegate.

To fix this I added a UINavigationController to my helper UIView, and added a UIButtonBarItem to call the popover for selecting a new item in the master view. It seems really simple in retrospect. The only tricky bit will be making the UIButtonBarItem hide when in landscape.

Related

UIBarButton unclickable in empty ViewControllers

i've created a tabBarController subclass and linked 3 viewcontrollers to the TabBarController in the storyboard. In the 3 ViewControllers which is directly connected with the tabBarController the UIBarButtons wont react when i click. They wont show the log message and does not do the highlight color. It seems like the navigationBar interaction is disabled or something. When i present a view modally on top of one of the 3 ViewControllers i have no problem with interaction with a UIBarButton in the modally presented View. I'm wondering what could result in such? i've struggled with this for ours.
i don't know if this has anything to do with it aswell, but in the modally presented views this does also result in white statusBar textColor, but it does not change it in the 3 views connected to the TabBarController.
What could this issue be?
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
self.navigationController.navigationBar.translucent = NO;
i've simply manually added a UIBarButton in the storyboard and then connected this action.
-(IBAction)testAction :(id)sender {
NSLog(#"test");
}
Try this
You just take 3 Navigation Controller as your tab bar view controller rather than simply view controller.
And connect tab bar view controller with navigation controller.
On navigation controller there is one view controller, on that navigation bar put your bar button item and connect to IBAction Method.
Its works for me.

TUITabBarController inside UINavigationController problems

I want to add UITabBarController as root view of my UINavigation controller. The purpose of that is that I want to make similar navigation as Facebook app: Then user select contact on Contacts tab - pushed view with user details doesn't have TabBar.
So, I have navigation controller, tab bar as a root view or it and couple TableViewControllers inside this UITabBarController.
I have two major issues with that:
I can't assign title for navigation bar for root views of tabbar. If I open contact details I have navigation bar title and no tab bar (as I wanted). But if I select Contacts or Favorites - those views have empty navigation bar title. I've tried to set it on viewDidLoad and viewDidApper without any success
Even worse issue. When I press Favorites table view insets are broken. first cell is under navigation bar. First loaded tableview (in my case Contact) displayed correctly. Adjust scroll view insets is YES for both TableViews.
Update:
Solution storyboard (note property "Hide Bottom Bar on the Push" is switched to YES).
I was also struggling with UITabBarController + UINavigationController issue. When UITabBarController was contained by UINavigationController, content insets were acting really weird.
I would suggest to use navigation controllers inside UITabBarController and when next controller is pushed, set 'hidesBottomBarWhenPushed' on that controller to YES.
This would also solve setting navigation bar title, as navigation controller is closer to view controller. You can just use self.navigationItem.
If you leave it to current setup - UITabController contained within UINavigationController, then you need to modify navigationItem on controllers tabBarController (self.tabBarController.navigationItem). Note that best place for it would be in view controllers 'viewWillAppear' for every controller contained within UITabBarController, as they share one navigation item.

add a view under tabbar in storyboard

I'm wondering if there's a way (preferably an easy one) to add a view under the tab bar, like shown on the attached picture, so that it stays there when I switch between tabs and when new view controllers are pushed/popped on each tab.
I have subclassed UITabBarController as "MainTabController" and set is as the custom class for the Main Tab Bar Controller Scene in my storyboard. Then in MainTabController's viewDidLoad I move the tabBar up and add the red subview. So far so good, but the main view area size is still like it was before, with the tab bar at the bottom, so now the last few elements of the table stay below the tab bar.
I would very much like to avoid adjusting the frame size for each and every controller I push into either of the tabs, so I hope that there's a simpler solution that I'm not aware of.
You can do this by embedding your tab bar controller in a custom container controller. You can do this in a storyboard by making a UIViewController the initial view controller, and adding a container view to it. Size that container view so it has whatever space you need underneath, and add your view in that space. Delete the view controller that comes automatically embedded in the container view, and control drag from the container view to your tab bar controller, and choose "embed".
Be aware that there's a bug in the way tab bar controllers layout their views in iOS 7. If you put a view near the bottom of one of the controllers, it will appear the first time you see it, but move down under the tab bar when you select another tab and then come back again (it will reappear if you rotate to landscape and then back again). You can get around this bug by making your container view controller (the initial controller in my storyboard) the delegate of the tab bar controller, and adding this code.
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // called by the embed segue
UITabBarController *tbc = segue.destinationViewController;
tbc.delegate = self;
}
-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
[tabBarController.view setNeedsLayout];
}

Beginner: How to add top bar with buttons on UITableViewController

I'm new to iOS development, I just have UITableViewController in a storyboard. I would like to add a top bar to it with some buttons, how to do that?
Notice, I'm using UITabBar that is created by "Storyboard" and my ITableViewController is one item of the UITabBar.
When you create the UITableViewController, do the following:
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:tableViewController];
and then instead of setting the table view controller as the view, set it to the navigation controller. Inside your table view controller, you can set the left and right buttons for the navigation bar to UIBarButtonItems (ask me if you want to know how to do that).
Select your UITableViewController and go Editor > Embed In and choose a navigation controller.
You might look at using the UINavigationController.
https://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UINavigationController_Class/Reference/Reference.html
If you do not want to use UINavigationController, then what you could do is create a view that has the "top bar" that you are looking for, then add the UITableViewController's view to your new UIView.
You need to create an UIViewController, not a UITableViewController, and then place the elements you desire however you want (in this case, a Table View and a UIToolbar).

TableViewCell disappears when push UINavigationController in UITabBarController's More tableview

I add 6 navigation controllers to UITabBarController's viewControllers. As normal, a More tab is created to list the last two. The problem is: after I select a table cell in the More table view, that cell's content fade out and disappear before the view controller push in. And then, after I back to the More table view by click the Back button, that cell's content show again. I guess the reason is More table view in its own navigation controller, and it push another navigation controller (created by me). I don't want to remove my navigation controller because I want to allow user rearrange tabs using the UITabBarController's Edit function. Can anyone suggest what I should do?
Create instances of your 6 navigation controllers in AppDelegate and retain them. And release in dealloc method
Just had the same problem. In my case I accidentally assigned the tabBarItem to the VC inside the navigation controller. When I instead initialized the tabBarItem on the navigation controller, the flickering / disappearing stopped.
MyViewController* viewController = [[MyViewController alloc] init];
UINavigationController* navigation = [[UINavigationController alloc] initWithRootViewController:viewController];
[viewController release];
// this has to be navigation.tabBarItem (not viewController.tabBarItem)
[navigation.tabBarItem initWithTitle:#"Title" image:[UIImage imageNamed:#"fancy.png"]
tag:42];
Initializing the tabBarItem on the viewController still showed the icon which made it harder to discover. I'm also not very sure (actually I think it's bad) about the way I initialize the tabBarItem (without alloc). But I had troubles with disappearing icons etc and hey, it works ;-)

Resources