ios - 将 UITableView 添加到 UIPageViewController 时,“无法识别的选择器发送到实例”

标签 ios objective-c uitableview uipageviewcontroller

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

 [self.pageViewController setViewControllers:[self.tableViews objectAtIndex:0] direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];

然后我使用 viewControllerBeforeViewController 将剩余的 UITableViews 添加到 PageViewController和 viewControllerAfterViewController方法。

然而 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'

为什么会发生此错误?

最佳答案

你应该先看看你使用的方法here :

- (void)setViewControllers:(NSArray<UIViewController *> *)viewControllers 
                 direction:(UIPageViewControllerNavigationDirection)direction 
                  animated:(BOOL)animated 
                completion:(void (^)(BOOL finished))completion;

它说参数应该是viewControllers

Parameters:

viewControllers The view controller or view controllers to be displayed.



所以,你必须采取UIViewcontrollerUITableViewController .

关于ios - 将 UITableView 添加到 UIPageViewController 时,“无法识别的选择器发送到实例”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45095132/

相关文章:

ios - 如何在 iOS SDK 中从 SimpleDB AWS 检索数据并显示它们?

iphone - 连续拍照时 iOS 应用程序崩溃

ios - 代码 : Return a Float from an NSMutableArray in heightForCellAtIndexPath

IOS/swift : Save the cell selection on UITableView

ios - 应用程序 didFinishLaunchingWithOptions 忽略 if 语句

ios - dyld:未加载库:@rpath/Alamofire.framework/Alamofire 引用自:

iphone - 从屏幕上删除键盘而不调用 resignFirstResponder

objective-c - '?:' 和 objective-c 中的 if 语句有什么区别吗?

ios:将新数据加载到 UICollectionView 中

ios - 使用自定义 UITableViewCells 子类 UITableView