0

メール コンポーザでは、「cancelbuttonclicked」の結果で MFMailComposerViewController を閉じたいと考えています。switch ステートメント内に実装できますか、それとも別のメソッドにする必要がありますか。また、閉じる前に送信ボタンでメッセージを送信したいと思います。

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
    switch (result) {
        case MFMailComposeResultSent:{
            UIAlertView *messageSent = [[UIAlertView alloc] initWithTitle:@"Message Sent" message:@"Your message has been sent" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [messageSent show];
        break;
        }
        case MFMailComposeResultSaved:{
            UIAlertView *messageComposeResultSaved = [[UIAlertView alloc] initWithTitle:@"Message Saved" message:@"Your message has been saved" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [messageComposeResultSaved show];
            break;
        }
        case MFMailComposeResultCancelled:{
            UIAlertView *messageComposeResultCancelled = [[UIAlertView alloc] initWithTitle:@"Message Cancelled" message:@"Your message has been cancelled" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
            [messageComposeResultCancelled show];
            break;}

        case MFMailComposeResultFailed:{
             UIAlertView *messageFailed = [[UIAlertView alloc]initWithTitle:@"Message Failed" message:@"Your message could not be sent" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
            [messageFailed show];
            break;
        }
    }
}
4

1 に答える 1

1

あなたのコードは正常に動作するはずです。UIAlertView内での使用に制限はありませんswitch。ただし、少し面倒にならないようにするために、次のように書き直すことをお勧めします。

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
    NSString *alertTitle = nil;
    NSString *alertMessage = nil;
    switch (result) {
        case MFMailComposeResultSent:{
            alertTitle = @"Message Sent";
            alertMessage = @"Your message has been sent";
        break;
        }
        case MFMailComposeResultSaved:{
            alertTitle = @"Message Saved";
            alertMessage = @"Your message has been saved";
            break;
        }
        case MFMailComposeResultCancelled:{
            alertTitle = @"Message Cancelled";
            alertMessage = @"Your message has been cancelled";
            break;}

        case MFMailComposeResultFailed:{
             alertTitle = @"Message Failed";
             alertMessage = @"Your message could not be sent";
            break;
        }
    }
    [[[UIAlertView alloc] initWithTitle:alertTitle 
                                message:alertMessage
                               delegate:self
                      cancelButtonTitle:@"OK"
                      otherButtonTitles:nil] show];
}

複数の を避けることができますinitWithTitle...

しかし、別の懸念があります: UIAlertViewis deprecated is iOS 8.UIAlertController代わりに使用する必要があります。この回答には使用例がありUIAlertControllerます。

于 2015-08-13T18:11:54.673 に答える