I placed two Table View\'s onto my main.storyboard. I then created two new .swift class files for them: VideoTableViewController and LinkTableViewController. How do I link t
If you want 2 tableviews in the same view controller do the following:
Create a UIViewController that is a delegate to
UITableViewDelegate, UITableViewDataSource
Add 2 IBOutlets for the UITableViews in your ViewController.h file like this:
@property (nonatomic, weak) IBOutlet UITableView *tableView1;
@property (nonatomic, weak) IBOutlet UITableView *tableView2;
Connect the IBOutlets to these.
Add the delegate functions for the tableview in the .m file somethng like this:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
if(tableView == self.tableView1){
return whatever1;
}
if(tableView == self.tableView2){
return whatever2;
}
}
@hackerinheels' proposed solution worked for me in a bit of a different setting: using a UITableView like a radio button group in a View Controller. It didn't work initially because I missed this step in hooking up the delegate and data source in viewDidLoad() of the View Controller:
tableView.delegate = self
tableView.dataSource = self
After this step is added, it started working nicely.
Even though this might be a no-brainer for experienced folks, but for a layman like me, spelling it out can be very helpful.
As for the solution for 2 TableViews in one View Controller, @hackerinheels' proposed 5 steps + the above change in viewDidLoad(), would work nicely!