点击按钮时iOS应用程序崩溃iPhone
我使用xcode 4.2和ARC。以下是我正在使用的代码。当我上的任何按钮点击我的应用程序崩溃,它强调在main.m文件点击按钮时iOS应用程序崩溃iPhone
这段代码有时我得到这个错误
-[__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文件 - 或者您更新它时,它会添加新版本的功能,而不会忘记旧版本。
基本上这个。在对nib文件进行更改后,或者对类定义进行更改后,很容易忘记对其他文件进行更改... – 2012-03-04 00:44:42
- 您不应该将一个视图控制器的视图添加到另一个视图控制器。
- 如果你还想这样做。你创建控制器,把它的视图,然后它发布,因为你没有存储引用。让伊娃
loginScreen
和ARC将为您保留ChooseLogin
控制器。
ok,然后如何在不添加视图的情况下实现此目的。 – 2012-03-03 21:53:19
[使用模态控制器](https://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html)。如果需要,你也可能需要制定一个协议来返回选定的值。 – 2012-03-04 07:01:38
我不知道我明白 - 为什么不把视图控制器的视图添加到另一个视图作为子视图?或者你是否说我不应该设置ViewController1.view = viewController2.view? – RonLugge 2012-03-04 07:11:11
您需要检查如何在Interface Builder nib文件中定义'UIView'子类,因为您可能已将自定义视图连接到不存在的选择器(方法)。当你点击视图时,你必须编写选择器。 – 2012-03-03 21:28:39
找不到它......你是说我打来的控制器可能有问题吗? – 2012-03-03 21:31:23
我编辑了我的问题,请检查 – 2012-03-03 21:39:17