I have an app where I need to have two tableviews swapped in and out by once view controller. I currently have it set so the viewcontroller is the delegate and datasource to both, so I use if / else statements in the delegate / datasource methods to determine which tableview to perform the action on like below:
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == [self selectAnAlbumTableView])
{
return [[self albums] count];
}
else
{
return ceil([[self album] numberOfAssets] / 4.0);
}
}
However, I saw this in another thread: "One method which I have often used is to actually have the delegates and data source for the two UITableViews be different objects. This way, your view controller doesn't have to switch back and forth, and your code is overall cleaner and simpler." My question is, how would you go about implementing something like this, ie separate objects for the delegate / datasource, and is it better than what I'm currently doing?