0

私のアプリにボタンがあり、それを押すとMFMailComposerViewControllerが表示され、作者が終了するとカスタム表示のMBProgressHUDが表示され、メールが正常に送信されたかどうかを確認します。メール作曲家を解散してHUDを表示するとアプリケーションがクラッシュする

作曲者の送信ボタンを押すとうまく動作し、メールが送信され、作曲者は却下され、HUDが表示されます。しかし、コンポーザービューでキャンセルボタンを押すと、コンポーザーは終了しますが、HUDは表示されず、アプリケーションがクラッシュします。

ここにはクラッシュのログがあります。

2012-02-02 22:49:34.821 App[5091:707] -[ViewController size]: unrecognized selector 
sent to instance 0x319210 
2012-02-02 22:49:34.831 App[5091:707] *** Terminating app due to uncaught exception 
'NSInvalidArgumentException', reason: '-[ViewController size]: unrecognized selector sent to instance 0x319210' 
*** First throw call stack: 
(0x340af8bf 0x342ff1e5 0x340b2acb 0x340b1945 0x340b27b8 
0x3748cfa5 0xf051 0x203d1 0x37553f5b 0x374f393b 0x374f37bf 
0x3746d81b 0x37472fb9 0x34bc4ba7 0x36ce3e8d 0x340822dd 
0x340054dd 0x340053a5 0x30889fcd 0x37486743 0xe7a7 0xe74c) 
terminate called throwing an exception 

ViewControllerは、メール作成者を表示するコントローラです。ここで

は、私が使用したいくつかのコードです:

-(void)showHUDWithMessage:(NSString *)msg 
{ 
HUD = [[MBProgressHUD alloc]initWithWindow:self.window]; 
[self.window addSubview:HUD]; 
HUD.delegate = self; 
UIImage *image; 
NSString *labelTextToShow; 

//Do something here 

UIImageView *imageView = [[[UIImageView alloc]initWithImage:image]autorelease]; 

HUD.labelText = labelTextToShow; 
HUD.customView = imageView; 

HUD.mode = MBProgressHUDModeCustomView; 
[HUD show:YES]; 
[HUD hide:YES afterDelay:3.0]; 
} 

-(void)mailFriend:(id)sender 
{ 
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc]init]; 
mailController.mailComposeDelegate = self; 

[mailController setSubject:@"Mail Subject"]; 

NSString *emailBody = @"Message"; 
[mailController setMessageBody:emailBody isHTML:YES]; 

[self presentModalViewController:mailController animated:YES]; 
} 

-(void)mailComposeController:(MFMailComposeViewController *)controller 
    didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error 
{ 
NSString *msg; 
switch (result) { 
    case MFMailComposeResultSent: 
     msg = @"Sent"; 
     break; 
    case MFMailComposeResultFailed: 
     msg = @"Fail"; 
     break; 
    case MFMailComposeResultCancelled: 
     msg = @"Cancelled"; 
     break; 
    case MFMailComposeResultSaved: 
     msg = @"Cancelled"; 
     break; 
    default: 
     break; 
} 

//Show HUD here 
[self showHUDWithMessage:msg]; 
[self dismissModalViewControllerAnimated:YES]; 
[controller release]; 

} 

メールが送信された場合、作曲ビューが正常に却下することができますので、HUDも正しく表示することができ、私は本当にここで間違っているのか分かりません... 。

ありがとう!

+0

何かが[サイズ]メッセージをviewControllerに送信しています。私はMBProgressHUDにはどこかにバグがあると思うでしょう。 Cmd + Shift + Fキーを押して「サイズ」を検索します。おそらくあなたの問題があるでしょう。 – CodaFi

+0

@CodaFiこれは問題だと思いましたが、「サイズ」というメソッドを見つけることができません... – Jing

+0

メソッドを遅延で呼び出すようにしてください。したがって、[self performselector:@selector(callHUD)withObject:self afterDelay:// time]のようになります。 – CodaFi

答えて

0

ほとんどの場合、これはメモリの過剰消去です。 NSZombieを有効にしてアプリをテストしてください。

いくつかのもの: どこにコントローラを作成しましたか?あなたはあなたが所有するオブジェクトをリリースする責任があります。あなたは自分のコントローラオブジェクトをしませんので、それを解放しません:
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error

[controller release]; // comment this line 

-(void)mailFriend:(id)sender自動解放で
-(void)mailComposeController:(MFMailComposeViewController *)controller 
    didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error 
{ 
NSString *msg = nil; // If result is not equal to any of the case statements then you want to pass nil to [self showHUDWithMessage:msg]; 
switch (result) { 
    case MFMailComposeResultSent: 
     msg = @"Sent"; 
     break; 
    case MFMailComposeResultFailed: 
     msg = @"Fail"; 
     break; 
    case MFMailComposeResultCancelled: 
     msg = @"Cancelled"; 
     break; 
    case MFMailComposeResultSaved: 
     msg = @"Cancelled"; 
     break; 
    default: 
     break; 
} 

//Show HUD here 
[self showHUDWithMessage:msg]; 
[self dismissModalViewControllerAnimated:YES]; 
[controller release]; 

} 

MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc]init];以降それを解放します。これはあなたが持っているかもしれない問題とは関係ありませんが。

0

MBProgressHUDへの参照をすべて削除し、単純なNSLogをメソッドに追加します。私は私のボトムドルのMBがこれを引き起こしていると賭けるでしょう。

もしそうでなければ、ここではメモリ管理が第2の選択です。 [コントローラのリリース]をコメントアウトする。

関連する問題