Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert UITableViewController into Other UIView

I've got a UITableViewController that inserts custom UITableViewCells into a UITableView. Is there a way that I can put this UITableController/View combo into different views? I've got the behavior of the UITableView acting the way I want, I just want to use that UITableView in different UIViews (say a UIView with a UILabel above the UITableView and one with a UILabel below the UITableView).

I know I can make a UIViewController that has an embedded UITableView in it and have the UIViewController act as the UITableView's delegate, but then I would have code reuse (the UITableViewController logic would be in multiple UIViewControllers). Or am I looking at this problem the wrong way?

I want to somehow reuse the functionality of my UITableView in different UIViews.

Thanks

like image 366
Tyler DeWitt Avatar asked Dec 08 '25 02:12

Tyler DeWitt


1 Answers

Yes, you can, simply instantiate (or get a reference to) the UITableViewController inside the UIViewController and call something like this:

[self.view addSubview:tableViewController.tableView];
like image 188
Moshe Avatar answered Dec 10 '25 18:12

Moshe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!