adding a UITableView programmatically to a UIViewController

前端 未结 5 1358
栀梦
栀梦 2021-02-02 17:37

I\'m loading a UIViewController into one of my Nav controller\'s hierarchies, which will contain some text and some images. At the bottom, I will want to create a expandable and

5条回答
  •  青春惊慌失措
    2021-02-02 18:16

    If you're like me and already had created a UITableViewController and then realizing that you did so much work on it that re-writing it would be a pain, you can just do the following to add the UITableViewController to the UIViewController as a subview.

    UITableViewController* tableViewController = [[UITableViewController alloc] init];
    [self.view addSubview:tableViewController.tableView];
    

    All the other answers above works great. I figure I'd add to this for those that have a heavily invested implementation of a UITableViewController and feel like refactoring would be a pain.

提交回复
热议问题