I have one UITableView class that can load a variety of data. All the actions on the data that is loaded will be the same regardless of what the data is, so I figured it would be best to keep it all in the same class. The problem I’m running into is that for one set of data, I need the UITableView to use the style UITableViewStyleGrouped, and the rest to use UITableViewStylePlain.
I was able to get this to work in prepareForSegue by using the following if statement:
if([whatToLoad isEqualToString:@"Sets"]){
[[segue destinationViewController] initWithStyle:UITableViewStyleGrouped];
}
else
[[segue destinationViewController] initWithStyle:UITableViewStylePlain];
But then Xcode gives me a warning on both of them of “Expression result unused”. Is there something else I can do to achieve the same result without the warning? Or do I have to create a different class for the one set of data that needs a grouped table?
You can have multiple table view controllers in the storyboard file, and set the “Class” to the same
UITableViewControllersubclass for each of them. So you can use the same controller code for each of them, but one has a “grouped” table view and the others have a “plain” table view.Calling
seems risky to me, because the destination view controller is an already allocated and initialized instance, and
initXXXfunctions are generally allowed to return a different instance.