Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Table view inside view, inside viewcontroller. Best way to do it?

I have a main home screen in my app which I am eventually hoping to contain a table view in the centre. When a button is pressed, the table view flips to a map view.

I would do this as part of the main view, but I want the surrounding area to stay the same. I have dragged a view into the centre of the homepage view controller, and have set up my table view there. How do I access the data in this view?

As far as I'm aware, there is no way of setting a tableviewcontroller to it. Any help would be greatly appreciated.

like image 378
Alex Godbehere Avatar asked Jan 09 '12 23:01

Alex Godbehere


People also ask

What is a tableviewcontroller in Android?

The TableViewController is an instance of the UITableViewController class that inherits UIViewController. We inherit the UITableViewController class when we need to display only tableview using our view controller and no other content since we can only add the tableview to a TableViewController in the interface builder.

What is the difference between view controller and container view controller?

Use content view controllers to present your app’s custom content onscreen, and use your view controller object to manage the transfer of data to and from your custom views. As opposed to a content view controller, a container view controller incorporates content from other view controllers into its view hierarchy.

How to access the Tableview in the storyboard?

The tableview in the storyboard can be accessed by using tableView property in the TableViewController subclass. The tableview is an instance of the UITableView class. TableViewCell: The tableview cell displays the actual content of the tableview controller. TableViewCell is an instance of the UITableViewCell class.

What is a view controller in UIKit?

Specifically, a view controller manages a view hierarchy and the state information needed to keep those views up-to-date. Every UIKit app relies heavily on view controllers to present content, and you frequently define custom view controllers to manage your views and UI-related logic.


1 Answers

You can make whatever View Controller is in charge of the views conform to UITableViewDelegate and UITableViewDataSource protocols in your header (.h) file:

@interface YourViewControllerClass : UIViewController <UITableViewDelegate, UITableViewDataSource>

And then implement the appropriate methods in your implementation (.m) file.

If you're using IB, drag the TableView's datasource and delegate outlets to your view controller subclass.

like image 182
Jack Lawrence Avatar answered Sep 28 '22 10:09

Jack Lawrence