0

アプリにボタンがあり、それを押すと MFMailComposerViewController が表示され、コンポーザーが閉じると、カスタム ビューの MBProgressHUD が表示され、メールが正常に送信されたかどうかがユーザーに通知されます。

コンポーザの送信ボタンを押すと問題なく動作し、メールが送信され、コンポーザが閉じられ、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];

}

メールが送信されれば、composer ビューは正常に閉じることができるため、HUD も正しく表示されるため、ここで何が問題なのか本当にわかりません...

ありがとう!

4

2 に答える 2

0

MBProgressHUD へのすべての参照を削除し、メソッドに単純な NSLog を配置します。一番下の MB がこれを引き起こしているに違いありません。

そうでない場合、メモリ管理は、ここでの私の明らかな 2 番目の選択肢です。[コントローラーの解放] をコメントアウトします。

于 2012-02-03T04:47:48.437 に答える
0

ほとんどの場合、これはメモリの問題を過剰に解放している可能性があります。NSZombie を有効にしてアプリをテストします。

いくつかのこと: どこで controller を作成しましたか? 自分が所有するオブジェクトを解放する責任があります。コントローラー オブジェクトを所有していないため、解放しないでください。

[controller release]; // comment this line


-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error

次へ

-(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];ます-(void)mailFriend:(id)sender。これはあなたが抱えているかもしれない問題とは何の関係もありませんが。

于 2012-02-03T04:22:29.310 に答える