2014-10-20 51 views
2

我試圖得到一個警報,UIAlertController彈出,但我不斷收到此錯誤:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nil modal view controller on target <States: 0x17557b90>.'UIAlertController拋出NSInvalidArgumentException

if([InAppPurchaseVerifier hasSubscription]){ 

    NSUInteger row = [indexPath row]; 
    NSDictionary *myDict = [[NSDictionary alloc] initWithDictionary:[self.fullList objectAtIndex:row]]; 

    NSString *state = [[NSString alloc] initWithString: [myDict objectForKey:@"0"]]; 
    NSString *stateDetails = [[NSString alloc] initWithString: [myDict objectForKey:@"1"]]; 

    OfficeInfo *anotherViewController = [[OfficeInfo alloc] initWithNibName:@"OfficeInfo" bundle:nil]; 
    anotherViewController.stateName = state; 
    anotherViewController.stateDetails = stateDetails; 

    [state release]; 
    [stateDetails release]; 

    [self.navigationController pushViewController:anotherViewController animated:YES]; 
    [anotherViewController release]; 
}else{ 
    UIAlertController* alert = [[UIAlertController init] alertControllerWithTitle:@"Subscription Needed" message:@"You need to subscribe in order to access that. If you already have a subscription you may need to restore it" preferredStyle:UIAlertControllerStyleAlert]; 
    [self presentViewController:alert animated:YES completion:nil]; // Error throws here 
} 
+1

'UIAlertController'僅在iOS 8中可用。您是否可能嘗試在早期版本的操作系統上運行它? – 2014-10-20 15:53:32

+0

是的,那一定是吧。我在我們的iOS 7設備上測試它...因此,舊的警報事件在8日貶值,但我們不得不使用它一段時間。很高興知道! – AndyD273 2014-10-20 15:59:42

+0

是的,你有一個支票和分支。這是蹩腳的。你可以寫一個包裝器。 – 2014-10-20 16:03:01

回答

8

UIAlertController僅在iOS版8適用於以前的版本,你必須檢查並回退到舊的代碼路徑,繼續使用棄用的API,或編寫一個快樂的小包裝器對象。

+0

感謝您的信息。即使它被折舊了,只是使用舊的UIAlertView for iOS 7和8的任何問題? – AndyD273 2014-10-20 16:05:49

+1

它仍然有效。 「任何問題」都取決於你個人對風險的容忍度。蘋果可能會拒絕您在某個時候使用已棄用的API(根據我的經驗,這是低風險)。 Apple可能會在SDK更新中刪除它,然後您必須更改您的代碼(中等風險,取決於您的發貨計劃)。所以,真的,只要看看自己,看看內部有什麼答案。 – 2014-10-20 16:30:52

相關問題