【问题标题】:NSInvalidArgumentException while Presenting ModalView呈现 ModalView 时出现 NSInvalidArgumentException
【发布时间】:2012-03-14 12:18:45
【问题描述】:

异常消息:

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[]{"blubb@blubb.de"});
        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 模拟器,但不适用于设备。

【问题讨论】:

  • 如果@Jason 回答无效,请发布完整的堆栈跟踪/崩溃日志。

标签: c# ios xamarin.ios mfmailcomposeviewcontroller messageui


【解决方案1】:

将此声明移到您的方法之外。一旦超出范围,它很可能会立即获得 GC。

MFMailComposeViewController view;

【讨论】:

    【解决方案2】:

    您的设备是否配置为发送电子邮件?请注意,即使是这样,您也不应该认为在每个用户设备上都是如此。

    IWO 你应该打电话给MFMailComposeViewController.CanSendMail 就像这是苹果公司的documented。两个重要的引述:

    您必须始终检查当前设备是否配置为使用 canSendMail 方法发送电子邮件

    如果 canSendMail 方法返回 NO,则不应尝试使用此接口。

    例子:

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

    【讨论】:

    • 天哪,我忘了在 iPad 上配置 EmailAccount。问题解决了。感谢您的帮助。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多