簡體   English   中英

單擊按鈕時iOS應用程序崩潰iPhone

[英]iOS application crashes when button is clicked iPhone

我正在使用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文件-或者您確實對其進行更新,並且它添加了新版本的功能,而不會忘記舊的功能。

  1. 您不應將一個視圖控制器的視圖添加到另一個。
  2. 如果您仍然想這樣做。 創建控制器,將其作為視圖,然后將其釋放,因為您無處存儲對它的引用。 使ivar loginScreen和ARC將為您保留ChooseLogin控制器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM