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.
Related
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.
I am getting this error while trying to create my app structure with story boards
static table views are only valid when embedded in
UITableViewController instance
I have created this sotry board that has a Navigation controller and then several views that branch off the main view that has a tableview in it.
one of the views that I have made off the main view has this error.. I have several other views with the same set up but none of them are having this issue yet.. im woudnering if I resolve this issue then they will say the same thing after as it was the first view I set up..
any help would be appreciated.
I was able to put a static UITableView inside my UIViewController by simply dragging the UITableView onto my ViewController in IB, and hooking both the delegate and data source to my view controller and then implement (even if i'm using a static table, just to make Xcode shut up)
#interface MyController : UIViewController <UITableViewDelegate, UITableViewDataSource>
#property (strong) IBOutlet UITableView *myTableView;
#end
If you wanted to put multiple UITableViews inside your ViewController with IB, you could create separate files/classes for each UITableView, and then hook them up as delegates. I see a bunch of answers that insist you must subclass from UITableViewController and it's just not the case.
#interface MyTableViewDelegate : NSObject <UITableViewDataSource, UITableViewDelegate, UIScrollViewDelegate>
When you say view, I'm assuming you mean UIViewControllers. For static tables, your view controller needs to be (must be) a UITableViewController, which is a subclass of UIViewController that handles tables, specifically static tables in your case.
I created a window based application, and I created a separate UITableViewController file called "HomeViewController" which right now only has a basic table.
In the MainWindow.xib file, I put a UIView in the bottom half of the screen, and I wish to put the HomeViewController tableview within this newly added UIView called "conferences".
Any suggestions as to how to push this file?
First off, usually your primary first view originates from a view controller that is loaded by the UIApplication object. The MainWindow nib's owner is UIApplication so you probably don't want to be mucking with the MainWindow nib. Rather, you want to muck with the view of the view controller loaded by MainWindow nib. If you look at the view displayed in IB for MainWindow.nib, it should say which view controller's view it is loading.
So, in IB for the view of view controller being loaded by MainWindow nib, this is where you want to place your UITableView. For purposes of this explanation, I will call this view controller, MucksViewController and associated nib, MucksView.nib.
I think what I would do, then, is drag and drop a UITableView into the view for MucksView.nib. Position it in the bottom half of the screen, as you described. Attach this UITableView to an IBOutlet property in MucksViewController header file. Next, drag and drop a UIViewController object into the main window for MucksView.nib. Make this UIViewController object's owner your HomeViewController class and also attach it to an IBOutlet property of type HomeViewController in MucksViewController's header file.
Now, in MucksViewController's class file, probably in viewDidLoad method, programmatically make the HomeViewController object the data source and delegate of the UITableView object.
But, I'm wondering, do you really need HomeViewController? It would be cleaner just to make MucksViewController the data source and delegate.
I hope this helps and is not too confusing.
Instead of a UITableViewController, use a UIViewController which implements the tableview delegate and datasource. in your MainWindow.xib, add a standard uitableview as a subview to the view where it should be. then also drag a HomeViewController to the xib (which should now be a uiviewcontroller sub class). click on the tableview, open the inspecor, go to connections, and drag the delegate and datasource to the HomeViewController in the xib.
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.
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?