I load a view from a XIB into a ViewController: the XIB is an IBOutlet of the viewcontroller.
The view contains two UITextFields and a UIButton. The button must invoke a function in the viewcontroller.
The textfields should respond to the typical textfields delegates, and in any case, communicate with the "parent" ViewController in a bidirectional way.
What's the best way to do this?
While it's quite clear for me how to deal with the button (I can use a delegate in the UIView class and conform the viewcontroller to the delegate), it's unclear for me how to deal with the textfield delegates.
Related
So I have five different UIViewController that I would like to create. Each of them has a common thing (an image view on top, a label on top). So I was thinking of creating a parent UIViewController and then have 5 subclass from the parent UIViewController. In this parent view controller it will have the UIImageView, the label, and everything common/shared with the other five. The question is, each of this UIViewController subclass will have it's own nib, however I want it to also have the parent's UIImageView in place. How do I then deal with this?
I guess I am confused if each of the subclass UIViewController has it's own nib, how can I see the parent view controller's xib in this subclass? I know my wording is extremely confusing, I can't seem to find a better way to explain this than this.
Don't create a xib for the parent view controller. Instead, subclassing the parent view controller, then creating a xib for the subclass will expose the IBOutlets from any of the parent classes/view controllers.
Just think of this example, as we've all subclassed UIViewController at some point and created a xib for it, we must connect the main view in the xib to the "view" IBOutlet. We'll that IBOutlet is defined in the UIViewController parent class.
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.
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.
Do I need a UITableViewController in addition to my UIViewController if I want to load a UITableView as a subview along with several other views at one time?
No, just make your UIViewController the data source and delegate of the UITableView subview, and make sure the UIViewController adopts the appropriate protocols in the header file.
Nearly all the UINavigationController examples out there show the use of initWithNibName:bundle: to load a NIB containing NOT an entire UIViewController (or subclass) but just a UIView, with the NIB's File's Owner Class property set to UIViewController (or the appropriate subclass) and its view outlet pointed at the UIView.
Why is this? Why can you not instantiate a full UIViewController (in particular, a UITableViewController) from a secondary NIB? And why do you even need to set the view outlet in IB? I don't understand the point of creating a blank white view which is going to be entirely ignored by a UITableViewController anyway.
In the MainWindow NIB, you can do both of the things that you seemingly can't do from a secondary NIB. You can setup a UINavigationController, and then within that you can setup a UITableViewController (or subclass). And you don't need to create an entirely superflous UIView object - rather helpful, since the whole point (I thought!) of a UITableViewController is that it creates and manages an associated table view for you using its delegate methods.
What is going on here? Am I being stupid? Is there some other way of doing what I want to? Or is there some logical reason for things being the way they are?
In IB create a new "Empty" nib and drag a "Table View Controller" into it from the Library.
Or am I misunderstanding the question?