Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios ';无法识别的选择器发送到实例';将UITableView添加到UIPageViewController时_Ios_Objective C_Uitableview_Uipageviewcontroller - Fatal编程技术网

Ios ';无法识别的选择器发送到实例';将UITableView添加到UIPageViewController时

Ios ';无法识别的选择器发送到实例';将UITableView添加到UIPageViewController时,ios,objective-c,uitableview,uipageviewcontroller,Ios,Objective C,Uitableview,Uipageviewcontroller,我正在尝试创建一个包含多个水平分页UITableView的PageViewController。UITableView存储在一个数组中;我使用UIPageViewControllerSetViewController方法将数组中的第一个对象添加到PageVC: [self.pageViewController setViewControllers:[self.tableViews objectAtIndex:0] direction:UIPageViewControllerNavigation

我正在尝试创建一个包含多个水平分页UITableView的PageViewController。UITableView存储在一个数组中;我使用UIPageViewController
SetViewController
方法将数组中的第一个对象添加到PageVC:

 [self.pageViewController setViewControllers:[self.tableViews objectAtIndex:0] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
然后,我使用
viewControllerBeforeViewController
viewControllerAfterViewController
方法将剩余的uitableview添加到PageViewController


但是,
setViewControllers
方法产生以下错误:

 -[UITableView count]: unrecognized selector sent to instance 0x7c347e00
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UITableView count]: unrecognized selector sent to instance 0x7c347e00'
为什么会发生此错误?

有两个问题

您需要将视图控制器而不是视图传递给页面视图控制器。对于每个UITableView,都需要一个UITableViewController

如果将变量
self.tableViews
更改为
self.tableViewControllers
(使用为每个UITableView创建的UITableViewController),您已经成功了一半


另一个问题是
setViewControllers
的第一个参数应该是NSArray。(NSArray有一个名为
count
的选择器)

更改代码,以便在添加第一个表视图时将其包装到数组中:

[self.pageViewController setViewControllers:@[ [self.tableViewControllers objectAtIndex:0] ] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil]
两个问题

您需要将视图控制器而不是视图传递给页面视图控制器。对于每个UITableView,都需要一个UITableViewController

如果将变量
self.tableViews
更改为
self.tableViewControllers
(使用为每个UITableView创建的UITableViewController),您已经成功了一半


另一个问题是
setViewControllers
的第一个参数应该是NSArray。(NSArray有一个名为
count
的选择器)

更改代码,以便在添加第一个表视图时将其包装到数组中:

[self.pageViewController setViewControllers:@[ [self.tableViewControllers objectAtIndex:0] ] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil]

您应该先看看您使用的方法:

-(void)SetViewController:(NSArray*)ViewController
方向:(UIPageViewControllerNavigationDirection)方向
动画:(BOOL)动画
完成:(作废(^)(BOOL已完成))完成;
它说参数应该是视图控制器

参数:

viewControllers要创建的一个或多个视图控制器 显示


因此,您必须使用
UIViewcontroller
UITableViewController
您应该先看看您使用的方法:

-(void)SetViewController:(NSArray*)ViewController
方向:(UIPageViewControllerNavigationDirection)方向
动画:(BOOL)动画
完成:(作废(^)(BOOL已完成))完成;
它说参数应该是视图控制器

参数:

viewControllers要创建的一个或多个视图控制器 显示


因此,您必须使用
UIViewcontroller
UITableViewController

显示用于创建TableView数组的代码,确保所有这些都正确创建并设置了数据源在
pageViewController
@user2181948中使用
tableview
作为
viewcontroller
看起来有点奇怪,它是否在viewControllers参数中工作?因为您使用了
UITableView
而不是
UIViewController
作为参数。@AnuragSharma现在由于未捕获的异常“NSInvalidArgumentException”,我收到了终止应用程序的错误
,原因:'-[UITableView parentViewController]:无法识别的选择器发送到实例
,这是一个完全不同的错误。您应该使用
viewController
作为参数!看看我的答案和Apple API文档。显示用于创建TableView数组的代码,确保所有这些都正确创建并设置了数据源在
pageViewController
@user2181948中使用
tableview
作为
viewcontroller
看起来有点奇怪,它是否在viewControllers参数中工作?因为您使用了
UITableView
而不是
UIViewController
作为参数。@AnuragSharma现在由于未捕获的异常“NSInvalidArgumentException”,我收到了终止应用程序的错误
,原因:'-[UITableView parentViewController]:无法识别的选择器发送到实例
,这是一个完全不同的错误。您应该使用
viewController
作为参数!看看我的答案和苹果API文档。
setViewControllers
不能是
NSObject
UITableView
NSObject
的子类
UIViewController
应该在参数中传递到这里。我没有注意到原来的问题有
UITableView
s而不是
UITableViewController
s。我已经修复了.OP已经提到的它是
UITableView
s。我的观点是,在发布答案之前,你应该自己检查两三次。
setViewControllers
不能是
NSObject
UITableView
NSObject
的子类
UIViewController
应该在参数中传递到这里。我没有注意到原来的问题有
UITableView
s而不是
UITableViewController
s。我已经修复了.OP已经提到的它是
UITableView
s。我的观点是,在发布答案之前,你应该自己检查2、3次。