我正在使用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
答案 0 :(得分:1)
-[__NSCFTimer parentLogin:]: unrecognized selector sent to instance
这意味着正在将消息发送到类无法识别的类 - 您要么没有编写此自定义选择器(函数),要么以某种方式将函数发送到错误的类,因此不承认。在尝试编写代码时,XCode通常非常适合捕获它们,但它似乎没有在XIB文件中检查它们。
根据我的经验,这种类型问题的最常见原因是当您删除或重命名某个函数时,忘记更新与该类关联的XIB文件 - 或者您确实更新了它,并添加了新的功能的版本,不要忘记旧功能。
答案 1 :(得分:0)
loginScreen
和ARC将保留ChooseLogin
控制器。