1

コードを書くとき、ランタイムエラーとして扱わなければならない状況がたくさんあります:alloc/initはnilを返し、リソースは見つからず、[someClass canDoThis]は絶対にNOを返します...iPhone - 実行時にエラーを処理する方法

このような状況では、exitWithMessageルーチン(警告ボックスが表示されます)が作成され、各クラスに割り当てられたメモリを解放するkillメソッドがあります。

そう... init方法では、あなたは例外のこれらの種類を持っている場合、私はあなたができるはず:

[self kill]; 
[OneClass exitWithFatalErrorMessage]; 
return nil; 

- (void) exitWithFatalErrorMessage:(NSString*)message 
{ 
    UIAlertView* alert = [[UIAlertView alloc] initWithTitle:NSLocalizedStringFromTable(@"Error" @"ErrorMessages", @"") message:message delegate:self cancelButtonTitle:NSLocalizedStringFromTable(@"Understood", @"ErrorMessages", @"") otherButtonTitles: nil]; 
    [alert show]; 
    [alert release]; 
} 

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    // stop the normal running of the app, there is a situation that would prevent it 
} 

- (void)kill 
{ 
    self.member = nil; 
    self.member2 = nil; 
    ... 
} 

しかし、これは動作しません...私の警告が(exitWithMessage表示されません。

これらのケースをどのように処理しますか?
はいの場合、警告が表示されないのはなぜですか(私はこの例のビューコントローラinitWithCoderメソッドに)?

答えて

0

コード内であなたが、代わりにexitWithMessageを呼び出し、このにそれを変更してみてくださいので、あなたは実際に、exitWithFatalErrorMessageメソッドを呼び出している:もちろん

[OneClass exitWithFatalErrorMessage:@"Message"]; 
+0

を...これはただの質問間違いです。 – Oliver

関連する問題