2012-03-14 23 views
1

異常消息:NSInvalidArgumentException而提出ModalView

Objective-C exception thrown. Name: NSInvalidArgumentException Reason: 
Application tried to present a nil modal view controller on target <Navigator: 0x1bed0d0>. 

這裏是我的代碼:

partial void BtnTest (MonoTouch.Foundation.NSObject sender) 
    { 
     MFMailComposeViewController view = new MFMailComposeViewController(); 
     view.SetToRecipients(new string[]{"[email protected]"}); 
     view.SetMessageBody("Hier steht nun der zusammengestellt text :)", false); 
     //view.MailComposeDelegate = new CustomMailComposeDelegate(); 
     view.SetSubject("Test"); 

     view.Finished += (s,e)=> 
        { 
          this.NavigationController.DismissModalViewControllerAnimated(true); 
     }; 

     this.BeginInvokeOnMainThread(()=> 
     { 
      this.NavigationController.PresentModalViewController(view, true); 
     }); 

    } 

它適用於iPad的模擬器,但不是在設備上。

+0

如果@Jason答案沒有工作,那麼請張貼完整的堆棧跟蹤/崩潰日誌。 – poupou 2012-03-14 15:14:19

回答

1

您的設備是否配置爲發送電子郵件?請注意,即使是這樣,你也不應該認爲每個用戶設備都會出現這種情況。

IWO你應該打電話MFMailComposeViewController.CanSendMail這是蘋果公司的documented。兩個重要的報價:

你必須經常檢查,看看當前的設備被配置爲發送電子郵件在所有使用canSendMail方法

你不應該嘗試使用這個接口如果canSendMail方法返回NO。

例子:

if (MFMailComposeViewController.CanSendMail) { 
     ... your code ... 
    } else { 
     ... show warning, like an UIAlertView 
    } 
+0

哦親愛的我忘記了在iPad上配置EmailAccount。問題解決了。謝謝你的幫助。 – Alex 2012-03-15 07:04:38

2

將此聲明移到您的方法之外。它很有可能一旦超出範圍就會讓GC得逞。

MFMailComposeViewController view; 
+0

不起作用。同樣的例外 – Alex 2012-03-14 12:41:01