简体   繁体   中英

How to add UITableView inside custom UIView?

I want to create common custom view with uitableview. I can do it using view controller and add subview as follows.

ViewController *vwCon=[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
vwCon.view.center=self.view.center;
[self.view addSubview:vwCon.view];

But after scrolling table view app become crash. So how can I add uitableview inside custom UIView?

You shouldn't add a view controller as a subview - in fact Im not sure whether you are allowed to at all. You need to present a view controller modally, or push it as part of a navigation controller. I doubt you really want that though- instead just use a UIView here rather than a view controller. Then you can add that as a subview to another view.

You also mention tableviews though. Have you looked at the storyboard? Its easiest to do all that in there - just drag a UITableview object from the objects list on the right hand side, into the main view controller.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM