簡體   English   中英

由於未捕獲的異常iOS終止了App

[英]Terminating App due to uncaught exception iOS

使用Parse並剛剛升級到XCode 6(已安裝Yosemite)。 直到那時我的應用程序都運行良好,現在它甚至都沒有加載第一個屏幕(登錄視圖控制器)。

這是錯誤消息:

2014-10-21 00:30:34.754 Hi App[393:143637] *** Terminating app due to uncaught exception      
'NSInvalidArgumentException', reason: 'Cannot do a comparison query for type: (null)'
*** First throw call stack:
(0x25e03e3f 0x334b1c8b 0x25e03d85 0x8d173 0x785fd 0x5fee3 0x292b785f 0x2934b51f 0x2934aff3  
0x2934ad5d  
0x2934acf1 0x2929f677 0x28cc7ccd 0x28cc36b5 0x28cc353d 0x28cc2f21 0x28cc2d25 0x29503395 0x2950413d  
0x2950e549 0x29502557 0x2c5450e9 0x25dca5b5 0x25dc9879 0x25dc83b3 0x25d16621 0x25d16433   
0x2930656f    
0x29301359 0x5d1b5 0x33a31aaf)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

這是我的loginviewcontroller.m:

   - (void)viewDidLoad
{
    [super viewDidLoad];
    self.navigationItem.hidesBackButton = YES;
}


- (IBAction)login:(id)sender {
    NSString *username = [self.enterUsername.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
    NSString *password = [self.enterPassword.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

    if ([username length] == 0 || [password length] == 0) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oops!"
                                                            message:@"Please enter a username, password."
                                                           delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alertView show];

  }
    [PFUser logInWithUsernameInBackground:username password:password block:^(PFUser *user, NSError  
    *error) {
    if (error) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry!"
                                                            message:[error.userInfo  
 objectForKey:@"error"]
                                                           delegate:nil cancelButtonTitle:@"OK"   
 otherButtonTitles:nil];
        [alertView show];
    }
    else {
        [self.navigationController popToRootViewControllerAnimated:YES];
    }
}];
}

我首先要仔細檢查以確保用戶名和密碼不為零。 當然,我看到您進行了檢查以確保密碼和用戶名長度不等於0。

此檢查的問題是您正在檢查,顯示UIAlert,然后其余代碼仍在執行

返回退出函數或將其余執行保留在else語句中。

試試看:

if ([username length] == 0 || [password length] == 0) {
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oops!"
                                                        message:@"Please enter a username, password."
                                                       delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];
    return;
}

我通過重建項目的一部分從技術上解決了它。 我不知道問題出在哪里,但它可能與舊文件與iOS 8混合使用有關(不確定是什么原因使它失敗了)。 我在iPhone 5 7.1中編譯了新項目,它可以正常工作。

暫無
暫無

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

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