将“dismissViewControllerAnimated:completion"发送到 UIViewController 后,“无法识别的选择器发送到实例 <OBJ_ADR>" [英] `unrecognized selector sent to instance <OBJ_ADR>`after sending `dismissViewControllerAnimated:completion` to a UIViewController

查看:12
本文介绍了将“dismissViewControllerAnimated:completion"发送到 UIViewController 后,“无法识别的选择器发送到实例 <OBJ_ADR>"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

很多类似的问题,但没有适合我的解决方案.

Lots of similar questions but non with a solution that works in my case.


我尝试编写一个简单的 FlipSideApp.只有两个视图,每个视图都有一个按钮 (flipBtn | flopBtn) 来呈现另一个视图,反之亦然.flip 在第一个视图上工作正常.另一个视图上的 flop 导致
无法识别的选择器发送到实例 0x6c3adf0.

I try to write a simple FlipSideApp. Just two views with a single button each (flipBtn | flopBtn) to present the other view vice versa. flip on the first view works fine. flop on the other view causes a
unrecognized selector sent to instance 0x6c3adf0.

在文件 FlipSide.m 中调用 [self deniedViewControllerAnimated:YES completion:nil]; 后,应用程序崩溃(请参阅下面的代码).其中 0x6c3adf0self 的当前地址,在这种情况下,它是 FlipSide : UIViewController 的一个实例.

The App crashes after calling [self dismissViewControllerAnimated:YES completion:nil]; in file FlipSide.m (see code below). Where 0x6c3adf0 is the current address of self which is an instance of FlipSide : UIViewController in that case.

所以我认为错误信息中提到的无法识别的选择器是dismissViewControllerAnimated:completion-method.
在输入 Xcode 的 CodeSense 时推荐"该方法.

So I think the unrecognized selector mentioned in the error message is the dismissViewControllerAnimated:completion-method.
While typing Xcode's CodeSense "recommends" that method.

根据UIViewController 类参考,此方法在 iOS 5.0 SDK 中是已知的.
我的部署目标是 5.0,设备 iPhone,基本 SDK iOS 5.0,架构标准 (arm7).

According to the UIViewController Class Reference this method is known in iOS 5.0 SDK.
My Deployment Target is 5.0, Device iPhone, Base SDK iOS 5.0, Architecture Standard (arm7).

为所有异常设置符号断点后,调试器将在主函数中的 UIApplicationMain 处停止.没有什么可以给我提示的.
僵尸对象已启用.即使我认为内存泄漏不是这里的问题.

With a symbolic breakpoint set for all Exceptions the debugger stops at UIApplicationMain in main function. Which is nothing that give me a hint.
Zombie-Objects are enabled. Even when I think memory leaks are not the problem here.

我该怎么做才能让选择器被识别?

What can I do that makes the selector be recognized?



文件:AppDelegate.m"

#import "FirstViewController.h"

- (BOOL)application:(UIApplication *)application  
                  didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  

self.window = [[[UIWindow alloc]  
                      initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

// Override point for customization after application launch.
UIViewController *viewController1 = [[[FirstViewController alloc]  
                 initWithNibName:@"FirstViewController" bundle:nil] autorelease];

self.window.rootViewController = viewController1;
[self.window makeKeyAndVisible];
return YES;
}



文件:FirstViewController.h"

@interface FirstViewController : UIViewController

- (IBAction)flipBtn:(id)sender;

@end


文件:FirstViewController.m"

…
- (IBAction)flipBtn:(id)sender {

NSLog(@"%s -- reached --", __PRETTY_FUNCTION__);

FlipSide* flipSide = [[FlipSide alloc] initWithNibName:@"FLipSide" bundle:nil];
[self presentViewController:flipSide animated:YES completion:nil];    

NSLog(@"%s -- done --", __PRETTY_FUNCTION__);
}



文件:FlipSide.h"

@interface FlipSide : UIViewController 

- (IBAction)flopBtn:(id)sender;

@end


文件:FlipSide.m"

#import "FlipSide.h"

- (IBAction)flopBtn:(id)sender {

NSLog(@"%s -- reached --", __PRETTY_FUNCTION__);

NSLog(@"self address is: %@", self);

//  //  //      ??? unrecognized selector sent to instance ???
[self dismissViewControllerAnimated:YES completion:nil]; //  <--

NSLog(@"%s -- done --", __PRETTY_FUNCTION__);
}



控制台输出是:

-[FirstViewController flipBtn:] -- reached --
-[FirstViewController flipBtn:] -- done --
-[FLipSide flopBtn:] -- reached --
self address is: <FLipSide 0x6c3adf0>
-[FLipSide flopBtn:] -- done --
-[FLipSide flopBtn:]: unrecognized selector sent to instance 0x6c3adf0 

推荐答案

我自己得到了解决方案

知道错误信息是有道理的:
答案在于使用的 XIB 文件.

Knowing it the error message makes sense:
The answer lies in the used XIB-file(s).

经验法则:
通过右键单击ctrl"+单击检查InterfaceBuilder中的GUI元素,确保它们发送的所有事件都连接到现有方法!

Rule of thumb:
Check your GUI-Elements in InterfaceBuilder by right-cklicking or "ctrl"+clicking that all their sent events are connected to existing methods!

如果不是这样
instance 表示 GUI 元素得到 sent a
unrecognized selector 表示在 InterfaceBuilder 中连接到它的不存在的方法.;-)

If that is not the case the
instance means the GUI element get sent a
unrecognized selector means a non existing method connected to it in InterfaceBuilder. ;-)

请注意,一个事件可以连接到多个方法.如果甚至没有定义其中之一(不再定义),您就会收到该错误.如果您手动删除、重命名或更改方法的签名,请记住这一点.之前建立的连接可能仍然存在.

Be aware that one event can be connected to several methods. If even one of them is not defined (any longer) you will get that error. Keep this in mind if you delete, rename or change signatures of methods manually. The formerly made connection may still exist.

这篇关于将“dismissViewControllerAnimated:completion"发送到 UIViewController 后,“无法识别的选择器发送到实例 &lt;OBJ_ADR&gt;"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆