Search code examples
objective-cxcodeuitableviewxml-parsingstoryboard

Loading UITableView to a View in another ViewController


In my storyboard file I have 2 viewcontrollers. A UITableViewController and a ViewController. I've completed all the needed coding for both of them. But I need to load the UITableView (and its data) inside a view in the ViewController. Any suggestions?


Solution

  • Yes you can do this by adding UItableViewController as its ChildViewController like this

    UItableViewController*vc1 = [[test1 alloc]initWithNibName:@"SecondViewController" bundle:nil];
    
    //add to the container vc which is self    
    [self addChildViewController:vc1];
    
     //the entry view (will be removed from it superview later by the api)
     [self.view addSubview:vc1.view]; 
    

    Swift:

    let tableViewVC = UITableViewController(nibName: "SecondViewController", bundle: nil)
    
    addChildViewController(tableViewVC)
    view.addSubview(tableViewVC.view)
    

    Hope it will help you.