MFMessageComposeViewController无法识别的选择器发送到实例

时间:2015-02-10 11:31:20

标签: ios swift selector mfmessagecomposeview

我的iOS Swift应用程序出了问题,我自己几个小时都无法解决。我有3个View Controller:

View 1 (List) ---> View 2 (Detail) ---> View 3 (Contacts)

在View 3中,我有一个带有AddressBook Contacts的UITableView。在选择MFMessageComposeViewController时打开一个Message窗口。如果我按发送/取消,MFMessageComposeViewController消失,我可以选择下一个联系人。

当我选择回到View 2并再次转发到View 3或者当我停留在View 3上时,选择一个又一个的联系人并发送消息没有问题。

但是当我回到View 1并再次导航到View 3时,我选择了一个联系人,MFMessageComposeViewController打开,现在,当我按发送/取消时,我得到了非常奇怪的错误:

Run 1: ...[__NSCFType numberOfSectionsInTableView:]: unrecognized selector sent to instance 0x17578c90...
Run 2: ...[UIScrollView numberOfSectionsInTableView:]: unrecognized selector sent to instance 0x14d88860...
Run 3: ...[__NSCFData numberOfSectionsInTableView:]: unrecognized selector sent to instance 0x1466af80...
Run 4: ...[UITableViewWrapperView numberOfSectionsInTableView:]: unrecognized selector sent to instance 0x16ebf910...
Run 5: ...[__NSCFDictionary numberOfSectionsInTableView:]: unrecognized selector sent to instance 0x17ea9920...

每次运行都是一次崩溃测试。正如您所看到的,每个错误都是不同的。

我的代码部分:

...
let msgComposerVC = MFMessageComposeViewController()
msgComposerVC.messageComposeDelegate = self
msgComposerVC.navigationBar.tintColor = UIColor.whiteColor()
msgComposerVC.navigationBar.barStyle = UIBarStyle.Black
msgComposerVC.recipients = ["\(phoneNumber)"]
msgComposerVC.body = body
if MFMessageComposeViewController.canSendText() {
    self.presentViewController(msgComposerVC, animated: true, completion: {
        UIApplication.sharedApplication().setStatusBarStyle(UIStatusBarStyle.LightContent, animated: false)
    })
}

...

func messageComposeViewController(controller: MFMessageComposeViewController!, didFinishWithResult result: MessageComposeResult) {
    controller.dismissViewControllerAnimated(true, completion: nil)
    if(result.value == MessageComposeResultSent.value) {
        // Send .. do something...
    }
}

感谢您的帮助!

更新

我忘记了:重新开始:当我转到详细信息(视图2),返回概述(视图1)并再次转到联系人(视图3)然后尝试将第一条消息发送给任何联系人同样的错误发生。

以下是我如何切换视图的代码:

// Change view from View 1 to View 2
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyboard.instantiateViewControllerWithIdentifier("View2Controller") as View2Controller
    vc.event = self.events[indexPath.row] // processing Data to VC
    self.showViewController(vc as UIViewController, sender: vc)
}

// Change view from View 2 to View 3
@IBAction func switchViewFunc(sender: AnyObject) {
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let vc = storyboard.instantiateViewControllerWithIdentifier("View3Controller") as View3Controller
    vc.event = self.event as NSManagedObject // processing Data to VC
    self.showViewController(vc as UIViewController, sender: vc)
}

更新#2:应用在controller.dismissViewControllerAnimated(true, completion: nil)

崩溃

1 个答案:

答案 0 :(得分:0)

我想我已经得到了......

问题不在于MFMessageComposeViewController或controller.dismissViewControllerAnimated(true, completion: nil)

在View 2和View 3上,我在NavigationController中创建自定义弹出窗口。我是在viewDidLoad做到的。现在,我正在viewWillAppear创建这些弹出窗口,并在viewWillDisappear的导航控制器视图中删除子视图。

似乎工作......