Zhen
Zhen

Reputation: 12431

Objective C: How do I add custom table view cells to a subview of a UIViewController

I currently have a UIViewController displaying a map view. I would like to display some custom table view cells when I tap on a button within the same UIViewController. Can I do that? Or do I need to set the table view cells within a UITableViewController?

Thanks for any advise here.

Zhen Hoe

Upvotes: 0

Views: 664

Answers (2)

albertamg
albertamg

Reputation: 28572

You should use a UIViewController subclass rather than a subclass of UITableViewController to manage a table view if the view to be managed is composed of multiple subviews, one of which is a table view. The default behavior of the UITableViewController class is to make the table view fill the screen between the navigation bar and the tab bar (if either are present).

I would like to display some custom table view cells when I tap on a button within the same UIViewController.

If you want to show your table view along with other views, you can add a UITableView subview and make your controller implement UITableViewDelegateand UITableViewDataSource protocols.

Upvotes: 2

FreeAsInBeer
FreeAsInBeer

Reputation: 12979

You need to create a UITableViewController, and then set the contents of the UITableViewCells using the - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath delegate method.

Upvotes: 1

Related Questions