概述:造成unrecognized selector sent to instance iphone,大部分情况下是因为对象被提前release了,在你心里不希望他release的情况下,指针还在,对象已经不在了。
很多时候,是因为init初始化函数中,对属性赋值没有使用self.foo赋值,而是直接对foo赋值,导致属性对象没有retain(心里以为retain了),而提前释放。
造成unrecognized selector sent to instance XXX,大部分情况下是因为对象被提前release了,在你心里不希望他release的情况下,指针还在,对象已经不在了。
问题解决链接:http://www.devdiv.com/thread-30546-1-1.html
问题的进一步分析:
@interface MyClass : NSObject {
MyObject *myObject;
}
@property (nonatomic, retain) MyObject *myObject;
@end
对于self.myObject = xxx调用。你将访问由@property这里面自动给你提供的一些函数。这些函数会帮你增加引用计数。
对于myObject = xxx这种调用。相当于你直接访问花括号里面的那个,即直接给myObject赋值但是没有增加引用计数。可能造成的情况就是在你要使用myObject之前,它已经释放了。
对于iPhone开发初学者来说,很想实现自己在iPhone上的第一个小程序,准备工作就绪侯就信心满满的开始了!一般来说大家可能都是从Hello World做起吧。
反正我是的,:),如果按照文档上的说明去做,一般也不会出现什么问题。也建议初学者这样开始,毕竟会增强我们自己的信心。
但是当我们自己独立去做一个Button实现响应事件的小程序的时候,有时候确给我们出现了一点点小问题。也就是我题目所说的。下边我就列出出现此问题的
错误代码以及解决方式。
//application delegate 中代码
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
MainView *mainView = [[MainView alloc]initWithNibName:@"MainView" bundle:nil];
[self.window addSubview:[mainView view]];
[mainView release];
// Override point for customization after application launch
[window makeKeyAndVisible];
}
//MainView controller 中代码如下
//@interface 中声明
- (IBAction)Click:(id)sender;
//@implementation 中实现
- (IBAction) Click:(id)sender
{
NSLog(@"Click Test");#import <UIKit/UIKit.h>
}
nib文件中也是正确连接相应的事件。
以上代码正常运行是没有问题,可是当你点击Click 按钮的时候确出现了如下错误:
"Terminating
app due to uncaught exception 'NSInvalidArgumentException', reason: '***
-[NSCFType buttonClicked:]: unrecognized
selector sent to instance 0x44e1e0'
这时候对于初学者来说这是莫名其妙,反复检查都是没有问题,但是就是会crash。
解决方法如下:
问题的原因就是声明MainView controller的时候出现问题。把MainView声明成立局部变量,
导致MainView中的action不能正确识别本身的ViewController
改正很简单:
MainView 定义在Application的.h文件中就可以了.
#import <UIKit/UIKit.h>
#import "MainView.h"
@interface TestAppDelegate : NSObject <UIApplicationDelegate>
{
UIWindow *window;
MainView *mainView; //在此定义
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@end
- (void)applicationDidFinishLaunching:(UIApplication *)application
{
mainView = [[MainView alloc]initWithNibName:@"MainView" bundle:nil];
[self.window addSubview:[mainView view]];
// Override point for customization after application launch
[window makeKeyAndVisible];
}
- (void)dealloc
{
[mainView release];
[window release];
[super dealloc];
}
希望对大家有帮助。
当然还有有很多其它情况出现类似的错误,原因基本都是由于viewController继承错误的导致的。
分享到:
相关推荐
-[AppDelegate setWindow:]: unrecognized selector sent to instance 0x60000002b440 修改方法: 在AppDelegate.h里加声明window @property (nonatomic, strong) UIWindow * window; 运行问题解决 兼容13和13以前...
reason: '-[NSNull length]: unrecognized selector sent to instance 分析原因发现,转化出来的OC对象中含有null.所以,NSNull没有length方法,所以会报找不到方法错误。 二、解决办法:将”null”替换成“ ”。 ...
前言 本文主要给大家介绍了关于iOS12适配及问题的相关内容,分享出来供大家参考学习,下面话不多说了,来一起看...1,-[_UIStatusBarIdentifier isEqualToString:]: unrecognized selector sent to instance 0x283452820
本文主要介绍了iOS中对象指针和基础数据类型如何进行强转,下面话不多说,直接来看示例详解。 一、对象指针的强转: ...-[UIView setText:]: unrecognized selector sent to instance 0x7ff1e14e03
-[MyProject.ViewController buttonTapped]: unrecognized selector sent to instance 0x7f9b42d48ae0 ...然后恭喜,您是iOS开发人员。 我们都讨厌选择器,现在您可以彻底消除它们。 用法 UIControl + Target....
1.相同具有外部链接的静态变量 ...iOS7.0以下『containsString』报 __NSCFString containsString:]: unrecognized selector sent to instance在要使用的时候导入#import “NSString+Extension.h” 的扩展即可 - (B
reason: '-[ViewController redBtn]: unrecognized selector sent to instance 0x7ff62ff05750' 多余的连线没有删除(创建了多余的IBAction) reason: '[<ViewController> setValue:forUndefinedKey:]: this class is ...
iOS Crash防护内容涉及 NSArray/NSMutableArray、NSDictionary/NSMutableDictionary、NSString/NSMutableString、Unrecognized Selector、KVO、KVC 、野指针定位、内存泄漏/循环引用;主要是对常见易错的地方进行...
主要介绍了解决python脚本中error: unrecognized arguments: True错误,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
前言 正在运行的 APP 突然 Crash,是一件令人不爽的事,会流失用户,影响公司发展,所以 APP 运行时拥有防 Crash 功能能有效降低 Crash 率,提升 APP 稳定性。但是有时候 APP Crash 是应有的表现,我们不让 ...出现原因
unrecognized arguments: –alluredir=reports 在pycharm的虚拟环境汇总安装好pytest,allure-pytest后, 命令行执行pytest “test.py” –alluredir=report 报错如下: 查找问题原因 直接通过错误信息看,是因为...
在使用IAR软件时总是会遇到一些错误,现在将它们汇总,可以直接查阅。
二、 如果AIK遇到 “unrecognized format. error!” 或 “ramdisk”问题 那么使用 mb 吧。这玩意似乎要MINGW,我cmd 里没跑通,MINGW里跑成功了!! unpack: ./mb.exe unpack /d/WPSSoftware/test/boot.img ...
windows socket错误码及出错原因,可以参考一下。也可MSDN。
主要介绍了JSON序列化Redis读取出错问题解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
linux移植碰到的3个问题解决 问题1:Error: unrecognized/unsupported machine ID (r1 = 0x00000356). 问题2:Starting kernel ... Uncompressing Linux... done, booting the kernel. 就停止了 问题3:Freeing ...
MATLAB开发的串口调试工具 % UART MATLAB code for uart.fig % UART, by itself, creates a new UART or raises the existing % singleton*. % % H = UART returns the handle to a ...% instance to run (singleton)".
我用这个代码进了proteus的仿真。ack部分改掉后才跑下去。WR部分可以跑过。RD部分老是提示unrecognized instruction.
You must configure either the server or JDBC driver (via the serverTimezone configuration property) to use a more specifc time zone value if you want to utilize time zone support. 内包含两种解决办法
<@listfiles...> <path_to_extract\> a Add files to archive c Add archive comment ch Change archive parameters cw Write archive comment to file d Delete files from archive e Extract files ...