ios不響應presentModalViewController介面的處理

來源:互聯網
上載者:User

   最近折騰ios的一個郵件分享和SMS簡訊分享功能,本來是很簡單的的功能,但是我發現開啟的郵件介面和簡訊介面一直不響應navigationController上面的按鈕,感覺很奇怪的,最後發現,需要在開啟的這些介面的委託實現方法中,把開啟的視圖關閉,說的有點彆扭吧! 我發一段代碼出來,大家可能會明白的!

注意:如果想調用傳送簡訊和郵件的功能,必須要引入一個庫:MessageUI.framework  

還需要import一些類:

#import <MessageUI/MessageUI.h>#import <MessageUI/MFMailComposeViewController.h>

如下代碼是ios傳送簡訊的代碼:

-(void)sendSMSComposerSheet{    MFMessageComposeViewController *messageCtrl = [[MFMessageComposeViewController alloc] init];    messageCtrl.messageComposeDelegate = self;    messageCtrl.body = @"share ....";    [self presentModalViewController:messageCtrl animated:YES];}

這段代碼實現的委託就:MFMessageComposeViewControllerDelegate

可是My Code中也實現了委託,代碼如下:

 

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{    }

但是開啟簡訊介面是沒問題的,關鍵是點擊簡訊介面的取消按鈕沒有相應,最後我想了一下,估計要在委託的實現方法中關閉開啟的視圖,結果的確如此!
以上代碼修改為:

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{    [controller dismissModalViewControllerAnimated:YES];}

或者:

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{    [controller dismissViewControllerAnimated:YES completion:^{}];}

兩種方式都可以的,這樣就能解決ios使用presentModalViewController開啟viewController,相應viewcongroller上面的相關按鈕了!

同時在附加上 ios發送郵件的代碼:

-(void)sendMailComposerSheet{    MFMailComposeViewController *mailCtrl = [[MFMailComposeViewController alloc] init];    mailCtrl.mailComposeDelegate = self;    [mailCtrl setSubject:@"郵件標題"];    [mailCtrl setMessageBody:@"郵件內容" isHTML:NO];    [self presentModalViewController:mailCtrl animated:YES];}

相關的委託:MFMailComposeViewControllerDelegate

介面的處理

-(void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{     [controller dismissModalViewControllerAnimated:YES];}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.