-4

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?

hmlasnk
  • 1,160
  • 1
  • 14
  • 33
  • see this link may be hepls you http://stackoverflow.com/questions/20737426/how-to-insert-the-uitextview-into-uialertview-in-ios – Anbu.Karthik Oct 05 '15 at 12:50
  • 2
    What is the error message you are getting when the app crashed. Please provide that Error Message also. – user4261201 Oct 05 '15 at 12:51
  • 1
    I think you're adding a child view controller without telling to the parent view controller. Take a look at here: http://stackoverflow.com/questions/17011579/add-a-child-view-controllers-view-to-a-subview-of-the-parent-view-controller – EDUsta Oct 05 '15 at 12:53
  • 1
    what is error messages.. we can get conclustion – SachinVsSachin Oct 05 '15 at 12:55
  • show us the code of how you added tableview and what is the crash log – Teja Nandamuri Oct 05 '15 at 12:57

1 Answers1

0

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.

Luke Smith
  • 1,218
  • 12
  • 17