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

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

问题描述

很多类似的问题,但不适用于我的情况.

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


我尝试编写一个简单的FlipSideApp.仅有两个视图,每个视图都有一个按钮(flipBtn | flopBtn),以呈现另一个视图,反之亦然. 在第一个视图上flip可以正常工作.在另一个视图上的flop会导致
unrecognized selector sent to instance 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 dismissViewControllerAnimated: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方法.
在键入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天全站免登陆