I'm new to iOS and objective-C and I'm having some trouble in understanding how controllers work.
In my code I have a UIViewController (with my custom controller assigned by storyboard) and inside it, together with other objects, I want to have a table handled by a different controller. What is the right way to do this?
The UITableViewController class itself is a subclass of UIViewController. Here's the class hierarchy of an example table view controller that displays contact information: an instance of ContactsTableViewController.
A view controller that specializes in managing a table view.
The UIViewController class defines the shared behavior that's common to all view controllers. You rarely create instances of the UIViewController class directly. Instead, you subclass UIViewController and add the methods and properties needed to manage the view controller's view hierarchy.
A TableViewController is a ViewController with a TableView built in. This will have the delegate methods needed already declared and setup. This VC is already a TableView delegate and datasource. It cannot be resized.
You can make that table view controller a child view controller of your UIViewController.
In the storyboard, you can do this easily by dragging a container view into your controller's view, and that will give you a child view controller automatically.
You'll want to:
If you need to get a reference to this table view controller from the UIViewController, you can do that in prepareForSegue
-- the table view controller will be the segue's destination view controller, and prepareForSegue
will be called right after the controllers are instantiated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With