ios - 应用委托(delegate) : unrecognised selector sent to instance

标签 ios appdelegate

我的应用程序委托(delegate)方法中有一些代码应该将对象发送到 View Controller 。由于某种原因,它抛出一个错误:“无法识别的选择器发送到实例”

在 View Controller 中我设置了以下变量:

@property (nonatomic, strong) Patient* patient;

我的应用委托(delegate)中的代码如下所示:

    UISplitViewController* splitViewController = (UISplitViewController*)self.window.rootViewController;
UINavigationController* patientNavController = [splitViewController.viewControllers objectAtIndex:0];
PatientMasterTableViewController* patientMasterTableViewController = (PatientMasterTableViewController*)[patientNavController topViewController];
PatientDetailViewController* patientDetailViewController = [splitViewController.viewControllers objectAtIndex:0];

Patient* firstPatient = [[patientMasterTableViewController patientArray] objectAtIndex:0];
[patientDetailViewController setPatient:firstPatient];// this line throwing the error

我是 iOS 的新手,我不太明白为什么它不允许我传递患者对象。谁能帮忙?

最佳答案

这行代码:

PatientDetailViewController* patientDetailViewController = [splitViewController.viewControllers objectAtIndex:0];

不保证返回 PatientDetailViewController。它可以返回任何类的对象,而您无需检查返回的是什么类的对象。

您的应用崩溃是因为它返回一个 UINavgationController 对象,该对象没有 setPatient 方法。

至于为什么它返回错误类的对象,这将取决于您创建的 View Controller 。

关于ios - 应用委托(delegate) : unrecognised selector sent to instance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26447524/

相关文章:

ios - 为 qmake TARGET 变量使用带空格的名称

ios - 在 UILabel 上使用外观代理是否会因为更改 UIAlertView 而拒绝我的应用程序?

iphone - JSonKit反序列化问题

ios - 核心数据 NSManagedObject 没有有效的 NSEntityDescription

ios - 归档应用程序时为 "Use of unresolved identifier"

iphone - 在没有 UIWebView 的情况下播放 YouTube 链接的视频

ios - Swift 单元测试 : module name of object class causes type check to fail

swift - 通过远程通知从 AppDelegate 推送到 UINavigationController

ios - Swift——在 App Delegate 中实例化一个没有 Storyboard的导航 Controller

swift - 如果我使用 TabBar 导航,如何从 AppDelegate 调用 viewcontroller 方法