我正在使用xcode 4.2和ARC。下面是我正在使用的代码。当我单击任何按钮时,我的应用程序崩溃,并在main.m中突出显示此代码
有时我会收到此错误
-[__NSCFTimer parentLogin:]: unrecognized selector sent to instance
有时应用程序崩溃而没有任何错误。
return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
我的代码是:
在我的ViewController.m中,我正在使用此代码访问ChooseLogin视图控制器。
- (IBAction)action:(id)sender {
ChooseLogin *loginScreen = [[ChooseLogin alloc] initWithNibName:@"ChooseLogin" bundle:nil];
[UIView beginAnimations:@"flipview" context:nil];
[UIView setAnimationDuration:2];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:NO];
[self.view addSubview:loginScreen.view];
[UIView commitAnimations];
}
然后在ChooseLogin.m中:
@implementation ChooseLogin
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (IBAction)parentLogin:(id)sender {
NSLog(@":::::::");
NSUserDefaults *prefs = [NSUserDefaults standardUserDefaults];
NSString *passwd = [prefs stringForKey:@"password"];
NSLog(@"data saved");
if (passwd == nil) {
CreatePassword *cPassword = [[CreatePassword alloc] initWithNibName:@"CreatePassword" bundle:nil ];
[UIView beginAnimations:@"flipview" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:NO];
[self.view addSubview:cPassword.view];
[UIView commitAnimations];
}else {
UserPassword *uPasswd = [[UserPassword alloc] initWithNibName:@"UserPassword" bundle:nil];
[UIView beginAnimations:@"flipview" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:NO];
[self.view addSubview:uPasswd.view];
[UIView commitAnimations];
}
}
- (IBAction)childLogin:(id)sender {
ChildLogin *loginScreen = [[ChildLogin alloc] initWithNibName:@"ChildLogin" bundle:nil];
[UIView beginAnimations:@"flipview" context:nil];
// [UIView setAnimationDuration:1];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.view cache:NO];
[self.view addSubview:loginScreen.view];
[UIView commitAnimations];
}
@end
最佳答案
-[__NSCFTimer parentLogin:]: unrecognized selector sent to instance
这意味着消息正在发送到该类无法识别的类-您尚未编写此自定义选择器(函数),或者某种程度上函数已发送到错误的类,因此无法识别。 XCode通常在尝试编写代码时很好地捕获它们,但是似乎没有在XIB文件中检查它们。
根据我的经验,此类问题的最常见原因是删除或重命名函数,而忘记更新与该类关联的XIB文件-或者您确实对其进行更新,并且它添加了新版本的功能,而不会忘记旧的功能。