iphone addSubView to delegate from another view controller - iphone

I'm trying to add a UIToolBar to my UITabBarController. Currently if I add it to the self.view in my UITableViewController and if you scroll down it will move the UIToolbar with it and disappear. So I need to add the UIToolBar to the UITabBarController from my UITableViewController, which is from a different controller. The UITabBarController is declared in the delegate.
Or is there another way to do this?

I would make the class with the table inherit from UIViewController, implement UITableViewDataSource, UITableViewDelegate, and put the tableview on self.view underneath a toolbar you've put on self.view.

Related

How to add a UIViewController as a subview to a UIViewController(RootViewController)?

I have a UIViewController named LoginViewController, and it is a rootViewController in the AppDelegate. In the LoginViewController, I have two buttons: Login and Enroll.
When I tap Login, I assign a TabBarController as the rootViewController, then show the TabBarController. However, now I think I need to add another UIViewcController as a subview when I tap Enroll. I tried the following:
[self.view addsubview:viewcontroller.view];
But the problem here is My ViewController's view.top is pinned about 20 pixels below the top of the screen. I think there is an issue with the status bar, but I can't figure out how to fix it.
I think that I need to add my ViewController as a subview to the LoginViewController, then redirect from there to different views. Can someone please suggest other options?
Try to set frame to your enroll screen object then add it as a subview to loginview.
Ex:
[enrollViewcontroller.view setFrame:CGRectMake(0,0,320,440)];
[self.view addsubview:enrollViewcontroller.view];
You should not make a UIViewController a subview of another UIViewController's view. What you likely want to do if treat the subview as a normal UIView (if not both of those views) so that you only have one UIViewController on screen and it occupies the entire screen.
More here: How to add an UIViewController's view as subview
Instead of adding a UIViewController as a subview to another UIViewController, I have decided to present my ViewController as a ModalViewController using
[self presentModalViewController:myViewController animated:YES];

UINavigationController set view height?

I subclassed UINavigationController and added a UIView to the bottom of its view in viewDidLoad (as a custom UITabBar or UIToolbar).
How do I set the height of the view of every UIViewController that this UINavigationController pushes?
How do I set the height of the view of every UIViewController that
this UINavigationController pushes?
View controllers don't have height -- the views they manage do.
To do what you propose, I suppose you override the accessors for the delegate property so that you could intercept any calls to -navigationController:willShowViewController:animated: and resize the child view controller. That doesn't seem like a very satisfying solution, though.
Do you have so many view controllers that you can't add your tool bar to each one's view hierarchy?

Subclassing UITableViewController for PopoverController

I have a ViewController that is composed of a few different views on my screen. A scrollView for text data, a TableView for some other data, etc. In my app, I want to add a UIPopOverController to show a list of my data. The current ViewController I am in is not a subclass of UITableViewController. Do I have to create a separate subclass of UITableViewController in another file, and use an instance of that class in this ViewController? Thanks.
You can show any kind of UIViewController in a UIPopoverController. A table view is not at all required for displaying a Popover controller. If you want to display a UITableviewController, you most certainly can. Just pass it in to the popover controller.

UINavigationController -> UIViewController -> UIView -> UITableViewController?

Inside Interface Builder I have a UINavigationController, which contains a UIViewController, which has a UIView inside it. This main UIView has a bunch of labels as well as a few ImageViews and custom UIViews as well.
What I want to do though is throw a UITableView inside this main UIView. This UITableView will take up about half the screen in the UIView. I'm trying to add a UITableViewController below the UIView but everytime I do it, the UITableViewController object replaces my UIViewController object in IB??
What am I doing wrong?
I want:
UINavigationController
UIViewController
UIView
UITableViewController (since the UTableView will be inside the preceding UIView)
Where am I going wrong in this setup? When I try to add the UITableViewController in IB I get:
UINavigationController
UITableViewController (..err? Why's it replacing my ViewController?)
Thanks in advance!
After putting UITableView into UIView instead of UITableViewController, and then set table view's delegate and data source to UIViewController.
Naturally, UIViewController should implements two protocol (table view deleate and data source).
You probably don't need table view controller at all. You have to add UITableView and implement all necessary data source and delegate methods in your view controller.

UIViewController takes up entire screen in Interface Builder

I have a NIB with a UIView that contains some UILabels, UIButtons etc. and a UIViewController that is loading a UITableView from a detached NIB.
I want the UITableView in the UIViewController to be positioned below my UIView, but whenever I add it in Interface Builder it takes up the whole screen, and my UIView becomes part of the UIViewController.
How can I make sure the UITableView in my UIViewController appears below the UIView?
I want the UIViewController to be
positioned below my UIView
What you mean is you want the UIViewController's view positioned below your existing UIView. View controllers do not show up on screen themselves.
Create a new UIView instance in your nib, position it where you want, and assign it to be the view for the view controller.