我正在使用prepareForSeque:sender:
动态设置UITableView
的委托和dataSource属性,然后再将其推入导航堆栈。永远不会调用委托方法,并且Xcode返回以下错误。不幸的是,Xcode并没有给我太多的堆栈跟踪信息,并且唯一指示什么对象被用作数据源的是UIViewControllerWrapperView
的实例,我认为这可能是情节提要库生成的。有任何想法吗?这甚至不可能吗?
错误:
*由于未捕获的异常'NSInvalidArgumentException'而终止应用程序,原因:'-[UIViewControllerWrapperView
tableView:numberOfRowsInSection:]:无法识别的选择器发送到
实例0x7f49370'
这是我的代码:
/**
* 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;
}
最佳答案
然后,您是否将尝试以更可靠的方式保留委托/ ds对象(例如将其保留在var / property array / dictionary中)?我相信委托不应由该对象保留,可能会发生所有reportContext被释放的情况。至少日志与内存管理问题完全匹配,我相信您自己也注意到了。
关于iphone - 从prepareForSegue:sender设置UITableView委托(delegate)和数据源时出错:,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/8782404/