亲子无法识别的选择器发送到实例

问题描述:

我有一个名为DataViewController的子视图和一个称为RootViewController的父视图控制器。亲子无法识别的选择器发送到实例

每次是试图调用一个函数或设置在我的RootViewController的定义,从我的子视图属性,我得到这些错误:

错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIPageViewController setDetailsDataObject:]: unrecognized selector sent to instance 0x6aa2df0'

代码:

RootViewController.h:

@property (strong, nonatomic) id detailsDataObject; 

DataViewController.m:

((RootViewController *)self.parentViewController).detailsDataObject = self.dataObject; 

而且......

错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIPageViewController showDetails]: unrecognized selector sent to instance 0x6880db0'

代码:

RootViewController.h:

- (void)showDetails; 

RootViewController.m:

- (void)showDetails 
{ 
    NSLog(@"Hello"); 
} 

DataViewController.m:

[((RootViewController *)self.parentViewController) showDetails]; 

有谁知道如何解决这些例外?

做一个Nsaasert语句来检查self.parentViewController实际上是RootViewController的实例

NSAssert([self.parentViewController isKindOfClass:[RootViewController class]], @"Not RootViewController"); 

尝试this..correct如果有任何拼写错误。

+0

感谢您的回复,我对xcode和iOS开发相当陌生,所以我从来没有听说过NSAssert或如何使用它,特别是在这种情况下。你能帮我多一些吗? – user1026090 2012-01-18 15:19:36

+0

再次检查我的答案..编辑了 – Shubhank 2012-01-18 15:27:16

+0

谢谢你的帮助,断言失败:断言失败 - [DataViewController handleSingleDoubleTap:],/Users/kevincuppens/Desktop/Catalogus/Catalogus/DataViewController.m:83 2012-01- 19 08:42:47.935目录[6063:f803] ***终止应用程序,由于未捕获的异常'NSInternalInconsistencyException',原因:'Not RootViewController' – user1026090 2012-01-19 07:45:00