Add other objects to iOS 5 storyboard after tableview - objective-c

I have a simple iOS 5 storyboard that contains a tableview controller scene. However, the table UI takes up 100% of the real estate and I am unable to add any additional objects such as a title bar. Any object that I drag to the scene will try to size correctly and what-not but as soon as I let go it will not add the object. What am I doing wrong?

If all you want is a title bar, then it looks like you want to embed your table view controller in a navigation controller. You can do this by selecting your table view controller and using the Editor: Embed In: Navigation Controller menu command. Once you do this, you should have a navigation bar, and you can double click it to edit the title.
If you need arbitrary UI elements along with your table view, then I think you need to use a plain UIViewController scene instead of a UITableViewController, and manually drag a UITableView into the scene. Your view controller would not subclass UITableViewController, instead it would subclass UIViewController and implement the UITableViewControllerDelegate and UITableViewControllerDataSource protocols. Also, you would need to manually wire up the delegate and dataSource outlets by ctrl-dragging from the table view to your view controller in interface builder, and your view controller would need a custom tableView outlet that points to the UITableView and is correctly wired up in IB. Perhaps there is a simpler approach than this though, if someone has a better suggestion that would be great to hear.

Related

Showing Toolbar on 2nd ViewController

I have two view controllers on the same storyboard. What I want to do is send an array of string values to the table view control on another view controller.
ViewController2 *second=[self.storyboard instantiateViewControllerWithIdentifier:#"View2"];
second.arrayFromVC1=areaArray;
[self presentViewController:second animated:YES completion:nil];
The second view controller has a toolbar control at the top by default. (See below.)
Passing data to another view controller wasn't easy for me, who has been using Xcode for two weeks. I somehow managed it. So an array of strings is sent to the 2nd view controller through an array variable (arrayFromVC1) set on the 2nd implementation file. I suppose experienced Xcode users know what I'm talking about. Anyway, the 2nd view controller does receive a list of values as shown below.
Well, the problems are that the toolbar control on the 2nd view controller will disappear when the user gets to see the list and that the table view control (UITableView) occupies the entire window. I understand that you can control the size of the table view control by specifying values under the viewDidAppear method. But my question is... Is that how things work with iOS and Xcode? So if I want to display that toolbar control at the top, I have to do it programmatically by writing code under the viewDidAppear method as well?
Thank you for your advice.
Tom
Tom, are you using interface builder and storyboards? If so, select the ViewController in IB, go to Editor (in the top menu) --> Embed In --> Navigation Controller.
This will embed the chosen VC and any VC it segues to (and so on) into a Nav Controller.

Create a UIViewController that contain a UIViewController

I have a UIViewController that allow me to display some text into a view.
I want to add an input method without add it directly into this view controller, this input method will be a button or a UITextField.
This input method will be a lot, but it will be use one at time chosing it from setting so a I won't to have a UIViewController that control all of this.
What I want is know how it's possible to split the output view (controller) with each input view (controller)?
You can image to have a text view on the top of the screen and some other view at the bottom and I will to separate the logic of the second view from the logic of the first one
Is it clear?
Of course it is possible to have 2 UIViewControllers on screen at any time! There are a few ways to go about this:
Using One Main View: Add the second ViewController's view as a subview
Using Interface Builder: Drag in a UIViewController Object, set it's class, then hook it's View outlet to a UIView in the first ViewController.
Child View Controller: As it's name implies, the -addChildViewViewController: method will add a new ViewController as well, then add it's view as a subview.
Yes, it's possible. Just add the controller as a child controller ([UIViewController addChildController:] and its view ([controller.view addSubview:childController.view]).

Changing rootviews view type in an iOS app

While creating a navigation based application, it automatically creates a root view controller which subclasses UITableViewController, but in MainWindow.xib as you know I can't see a UITableView is placed under root view controller but we drag and drop a table view there. Can we simply drag and drop a UIView instead of a UITableView and change the root view controller class to sublass a uiview instead of UITableView and change its methods?
Or I must drag a UITableView in IB for the root view controller? I am a beginner and I do not want to make complicated things so what is the simplest way of using a UIView as a root. If thats not simple I will stick with the table view.
Yes you can change. You just need to change some bindings in inteface builder and change rootViewController's superclass to UIViewController instead of UITableViewController.
UPDATE
First open the rootViewController.xib and delete the tableiew from there and drag-n-drop a UIView. Bind that View to view property in file-owner. Change superclass of rootViewController from UITableViewController to UIViewController. That's it.
Here are the screenshots.

UISplitViewController: how to get toolbar if details controller is UITableView?

I checked out Apple's example on how to exchange detail views in the UISplitViewController and it seems that they put the UIToolbar in every detail controller. Then, if the device is rotated, they hide the toolbar or show it and add a popover button which will show the root controller.
I'd like to adopt this pattern to show my root controller in a popover using a button in the toolbar, but unfortunately, my detail controllers are all UITableViewControllers and they do not allow adding other UI elements than a table view. So how do I deal with that? Is there an example around?
René
I think I figured out by myself: DON'T use a ´UITableViewController´ and a UITableView as root view in your NIB, as you cannot add a UIToolbar to the table view.
Instead: In the NIB, put a standard view and drag a UIToolbar and a UITableView on it.
Connect the standard view to the controller's "view" outlet.
Add another outlet and make it a UITableView. Connect the table view to it.
In the code: Let your controller inherit from UIViewController and not from UITableViewController.
Add a property to your controller to get the TableView to make it look compatible to UITableViewController.
public UITableView TableView
{
get { return this.viewTableView; }
}
Upon the viewDidRotate event you will have to adjust the table views width and height now (UITableViewController did that job for you before):
this.TableView.Frame = new RectangleF(0, 44, this.SuperView.Frame.Width, this.SuperView.Frame.Height);
The 44 pixels com from the parent view's toolbar.
I don't miss UITableViewController. I know there are some issues like automatic scrolling when editing, but in my case this is simply not needed.
René
Check out this example and the corresponding code. If I understand your question, this should show you how to do what you're looking to accomplish.
Also, just as an FYI to everyone, another MT user MonoTouched the MultipleDetailViews example that you linked to above.

Programmatically change subviews from within subview's controller

In my iPhone application I've set up a default, blank view called Main View into which various child subviews will be loaded for different parts of the application. It's the same approach as if I was using a tool bar to switch between subviews. That case, in the MainView controller I could hook IBActions to buttons in the toolbar, so that when a button was pressed, MainView added different subviews to itself.
In my situation, though, I need to tell MainView to change its subview from within the subviews. So here are two sister subviews, each with their own controller and xib, that would be loaded as subviews of MainView:
- StartView
- FormView
In StartView, after some animations and welcome stuff, a button triggers the camera image picker. Once the image picker returns the image, I need to tell MainView to remove StartView and add FormView.
It may be the result of a long day or my newness to iPhone OS but I'm stuck getting my head around the right way to set up my objects/controllers.
You never have more than one view controller active at a time. (The nav and tabbar controllers don't control views, they control other controllers.) In this case, you will have a single controller that has the MainView as its view property. It will add StartView and formView as subviews of MainView.
However, this is not a good design. It will overload the MainView controller by forcing it to juggle many views. It would be better to use a hidden navigation controller or a tabbar. Hierarchies of controllers can create the illusion from the users point of view for almost any interface layout you can imagine. There is no need to create a logical structure that mimics the visual one.
From your description you may only need a single view/view-controller pair: Set the formView controller to open the camera view before it displays the formView. When the camera is dismissed it reverts to the formView automatically. No fuss, no muss.