gpt4 book ai didi

iphone - 单击按钮时 iOS 应用程序崩溃 iPhone

转载 作者:行者123 更新时间:2023-11-29 13:39:36 25 4
gpt4 key购买 nike

我正在使用 xcode 4.2 和 ARC。下面是我正在使用的代码。当我点击任何按钮时,我的应用程序崩溃并突出显示 main.m 中的这段代码

有时我会收到这个错误

-[__NSCFTimer parentLogin:]: unrecognized selector sent to instance

有时应用程序会在没有任何错误的情况下崩溃。

return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

我的代码是:

在我的 ViewController.m 中,我使用此代码访问 ChooseLogin View Controller 。

- (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 文件——或者您更新了它,它添加了新的函数的版本,不要忘记旧版本。

关于iphone - 单击按钮时 iOS 应用程序崩溃 iPhone,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9549988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com