Resizing viewControllers view that are part of a UINavigationController on IPhone - iphone

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.

Related

Show UITabBar on UIViewControllers that are not part of the UITabBar?

I have an iOS app written in Swift with UITabBarController with 5 UIViewControllers. Now, I have a bunch of UIViewControllers that are not part of the UITabBarController. I'd like to be able to show that same tabbar but I have no idea how to do that. Any clue?
More details: This is one of the View Controllers that the tabbar has. I use storyboard references and split my view controllers into separate more manageable storyboards.
So, the big picture:
There's no initial ViewController since I use storyboardId to get to the initial Navigation Controller. From there we have a ViewController embedded in the same Navigation controller. In that ViewController, there are 2 Container views - one of the size of the bottom ViewController that contains the "hamburger" button that toggles the other Container View which has an embedded UITableView in. When a specific cell is selected it should go to Profile ViewController that's not even in the same storyboard. The segue is set to be Push. Either way, doesn't show the UITabBar on the Profile ViewController
how you doing?
I don't know if I understood, but you are trying to show tabbar after going to another screen, right? If the answer is 'yes', try to change your segue to show(e.g. push).
-----Edit-----
You can do with two ways:
Presenting Modally -> using Current Context
Use push(e.g.) with a navigation view controller, you can also hide the navigation bar if you go to Navigation controller -> Attributes inspector -> Navigation Controller -> Uncheck Shows Navigation Bar
Hope now it works!
Best regards

Put common code for UINavigationBar in UINavigationController

In my iPhone project, I have a navigation view controller. In each view that is loaded by this controller, I am setting buttons in the UINavigationBar that are doing different things for each view.
However, I want to have the .rightBarButtonItem do exactly the same thing each time (namely, pop up a UIActionSheet). How can I centralize this code and not have to put it in every view controller?
I tried subclassing UINavigationController and setting the .rightBarButtonItem in this subclass' viewDidLoad. However, no button is displayed then. (But when I put the same code in a view controller loaded by the navigation controller, the button is displayed and works fine).
The code I am using to set the rightBarButtonItem is:
self.navigationItem.rightBarButtonItem = ...
Subclass all the UIViewControllers that are pushed onto that UINavigationController and add the same viewDidLoad code.

a view containing UITableView and UITabBar

I am using UINavigationController to push and pop other UIViewControllers in my app.
In one of the UIViewControllers I am using UITabBar to switch between different views. One of the view has UITableView and I am having difficulty showing the tabBar at the bottom. Even if it shows up it scrolls up and down with the tableCells.
I didn't use the tabbarcontroller because apple documentation recommends not to push tabbarcontroller on to navigationcontroller stack.
Thank you.
I guess that you are using UITableViewController. The View of the UITableViewController is the tableView itself, so when you add the tab bar to the view you actually add it to the table view. that is why it scrolls with it.
you should create a regular UIView, and then add the tableView and the tab bar to that view.
shani

Iphone UIViewController to UINavigation controller programmatically

I have been stuck on this for a few days now and it is killing me... In my viewDidLoad event, I am trying to programmatically add a full screen UINavigationController to a subview of my view controller. So far, I have only succeeded in doing two things...
1) Only a grey screen shows up
OR
2) I get something that resembles a navigation controller added to the view controller, instead of being my navigation controller from a XIB it is just a generic one... even though I loaded from the XIB. Oddly enough it is always shifted 25 pixels downward and slightly cut off.
I have read every single link on google and I can't seem to figure this out. I just created a new viewcontroller... added a UINavigationController to it... try to load that view controller and it messes up.
Any help is greatly appreciated!!!!
Instead of having the UINavigationController be a child of some other view controller, make the UINavigationController the root controller itself. The navigation controller is one of the special "container" view controllers, and it generally wants to own the whole screen and be at the root of the controller hierarchy (except in certain circumstances).
Try something like this:
UINavigationController * rootNavController = [[UINavigationController alloc] initWithRootViewController:myRootControllerInTheNavController];
[window addSubview:[rootNavController view]];
Which will obscure any existing views with the nav controller (those existing things will still be there when you -removeFromSuperview the nav controller's view). The nuclear option is to set your UIWindow's rootViewController property with the nav controller, but it sounds from your comment that this may not be what you want to do here.
Possibly a cleaner approach: If it accomplishes what you want, I believe you could also take your nav controller and present it modally (see docs for uiviewcontroller) from whatever the current view controller is. Set the transition appropriately, and while you're in the nav stack, the nav controller will be visible.

Switching Views within UITabBar View

I have created an UITabView application. Each view selected from the bar is a seperate controller with own nib file. I switch between them succesfully.
In the first view I have two buttons (check out the screenshot). When clicking them I want to switch to another views which are the parts of the current view controller. I use:
[self presentModalViewController:anotherViewController animated:NO];
That switches the view, but hides the UITabBar. How to keep the bar on the screen after the switch?
P.S. Sorry for the blurred image. I am not allowed to share to much info.
Well I think you are misusing the modal view controller. For a problem like this I'll say you should put them in a view controller stack using UINavigationController. Instead of making each tab a UIViewController make it a UINavigationController, then you can push and pop view controllers on it, which still show the tab bar.
See http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UINavigationController_Class/Reference/Reference.html
use: tabBarController.selectedViewController = newViewController
edit: UINavigationController is not needed here.