I'm using prepareForSeque:sender:
to dynamically set the UITableView
's delegate and dataSource properties before it gets pushed onto the navigation stack. The delegate methods are never called and Xcode returns the error below. Unfortunately, Xcode doesn't give me much of a stack trace and the only indication of what object is being used as the data source is an instance of UIViewControllerWrapperView
which I think may be something generated by the storyboard library. Any ideas? Is this not even possible?
The error:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIViewControllerWrapperView tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0x7f49370'
Here's my code:
/**
* Handle the various segues
*
* @author Jesse Bunch
**/
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the selected cell
NSIndexPath *selectedIndexPath = self.tableView.indexPathForSelectedRow;
ReportTableViewCell *cell = (ReportTableViewCell *)[self.tableView cellForRowAtIndexPath:selectedIndexPath];
// Instantiate the selected report's context
// TODO: Insert error handling here
Class reportClass = NSClassFromString([cell.reportInfo objectForKey:@"ReportClass"]);
BaseReportContext *reportContext = [[reportClass alloc] init];
reportContext.delegate = self;
// Get the destination options controller
ReportOptionsTableViewController *optionsController = (ReportOptionsTableViewController *)segue.destinationViewController;
// Let the report context be the delegate of the options controller
// The report context should contain all the information needed
// to display the necessary report customization options
optionsController.tableView.delegate = reportContext;
optionsController.tableView.dataSource = reportContext;
}