Reputation: 1666
I need to have two Table Views in one XIB file, is there any way to do that?
Upvotes: 0
Views: 4076
Reputation: 1
I have created two tables & map both tables delegate & datasource to file owner in .xib file at this stage i got the error. i resolved it by : Add two table view in header file(IBOUTLEt) for identifying the tables For 1st table Map datasource & delegate through .xib file for 2nd table i describe in .m file. it is running fine.....
Upvotes: -3
Reputation: 14509
Another cleaner way to do is to add two different UITableViewController to the XIB and set it to different classes.
Your XIB should look like this. Instead of connecting the table view datasource and delegates to File's owner, you connect it to their own controllers.
This way, your code will be clean and easy to maintain. Later on if you want to move that table to a different view, it's very easy and can be done just by changing IB.
Upvotes: 2
Reputation: 4577
Yes It is possible. You just need to check with tableview name or tag to differentiate tableview in datasource and delegate method. For example for numberofRowsInSection Datasource method you can do like this.
- (NSInteger)tableView:(UITableView *)tableview numberOfRowsInSection:(NSInteger)section {
if(tableview==firstTableview)
{
return 4;
}
else {
return 6;
}
}
So you just need to check like this for every datasource and delegate method. Hope this help.
Upvotes: 3
Reputation: 12787
Simple go to library select tableView and drop in xib and set a tag=1 and then get other table on drob on xib the set tag=2
you can differentiate by tag or by their ivar name;
so make proper if else condition in table's datasource methods and delegates. also you can hide any one for specific situations.
Means use your brain and logic.
Upvotes: 1