Insert UITableViewController into Other UIView

2019-03-16 20:39发布

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

1条回答
甜甜的少女心
2楼-- · 2019-03-16 21:25

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];
查看更多
登录 后发表回答