Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Embedding TableView in TableViewController into another view

I would like to customize content of table view controller(add some buttons, etc.) but root view for that is table view. Is it a way to embed it into another view and add controls on it?

like image 614
famer Avatar asked Nov 19 '14 11:11

famer


2 Answers

You can use Container View.

In the storyboard create another view controller that you would use to host those controls. Then drag in Container View from the Object Library (normally the last item in the list) and place it where you want the table view to appear (which could be the whole screen). Doing this, the Container View will create another view controller. Simply delete that and ctrl drag from the Container View to your table view controller and select embed segue.

By doing this, you would not have to change anything in your current table view controller if it doesn't depend on other view controllers to give it data in order for it to work. If it does, however, you could assign the segue identifier to the embed segue, implement prepareForSegue:sender: and do whatever you would normally do with other segues.

like image 56
yusuke024 Avatar answered Oct 30 '22 09:10

yusuke024


You simply add TableView as a subview of a uiviewcontroller. Remember to call for delegates. Normally i don't use storyboards, but if you do it programmatically you can do like this:

On .h file:

@interface EmbeddedTableView : UIViewController <UITableViewDelegate, UITableViewDataSource>  

And on .m file simply create your tableView by adding it as subview of viewcontroller.

You can look at this for example: How to set up UITableView within a UIViewController created on a .xib file

like image 22
Federica Venuto Avatar answered Oct 30 '22 10:10

Federica Venuto