Ios 设置tableviews数据源和委托的适当方法
好的,我有tableview控制器1。在tableview控制器1的DidSelectRowatineXpathMethod中,我尝试使用表视图调用popOver,具体取决于数据是否符合要求,如下所示:Ios 设置tableviews数据源和委托的适当方法,ios,objective-c,uitableview,uiviewcontroller,Ios,Objective C,Uitableview,Uiviewcontroller,好的,我有tableview控制器1。在tableview控制器1的DidSelectRowatineXpathMethod中,我尝试使用表视图调用popOver,具体取决于数据是否符合要求,如下所示: UIViewController *popoverContent=[[UIViewController alloc] init]; UITableView *tableView=[[UITableView alloc] initWithFrame:CGRectMake(265,
UIViewController *popoverContent=[[UIViewController alloc] init];
UITableView *tableView=[[UITableView alloc] initWithFrame:CGRectMake(265, 680, 0, 0) style:UITableViewStylePlain];
UIView *popoverView=[[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 300)];
popoverView.backgroundColor=[UIColor whiteColor];
FirstTVController * firstTV = [[FirstTVController alloc]init];
// popOver.keyId = model.key_id;
popoverContent.view=popoverView;
popoverContent.contentSizeForViewInPopover=CGSizeMake(200, 420);
[tableView setDelegate:firstTV];
[tableView setDataSource:firstTV];
popoverContent.view=tableView; //Adding tableView to popover
UIPopoverController *popoverController=[[UIPopoverController alloc] initWithContentViewController:popoverContent];
[popoverController presentPopoverFromRect:CGRectMake(340, 400, 0, 0) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
现在,当我将tableview数据源和委托更改为self时,它就可以工作了。但当我设置表视图数据源和委托方法时,我会得到一个返回UIApplicationMainargc、argv、nil、NSStringFromClass[AppDelegate class];EXC_糟糕的访问我做错了什么
@interface FirstTVController : UITableViewController <UITableViewDataSource, UITableViewDelegate>
此方法结束时,firstTV超出范围。因此,表视图的数据源和委托属性指向无效对象
您必须选择以下可能的选项:
将firstTV设置为实例变量,这样它就不会超出范围。
更好的方法是使用自定义类扩展UITableViewController来清理问题中的所有代码。没有理由创建一个通用的UIViewController,向其中添加您自己的表视图,然后使用另一个类作为表的数据源和委托。把所有这些都集中到一个类中。