I got a problem with my iOS Swift App and i can't solve it by myself for hours. I have 3 View Controller:
View 1 (List) ---> View 2 (Detail) ---> View 3 (Contacts)
In View 3 I have a UITableView with my AddressBook Contacts. On select a MFMessageComposeViewController open a Message window. If i press send/cancel the MFMessageComposeViewController disappear and I'm able to select the next Contact.
When I tab back to View 2 and forward to View 3 again or when I stay on View 3 there are no problems selecting one contact after another and send a message.
But when I tab back to View 1 and navigate to View 3 again I select a contact, the MFMessageComposeViewController opens and now, when I press send/cancel, I got very strange errors:
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...
Every Run is a test with crash. As you can see every error is different.
My Code parts:
...
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...
}
}
Thanks for help!
Update:
I forgot: On a fresh run: When I go to Detail (View 2), back to Overview (View 1) and again to Contacts (View 3) and then try to send the first message to any contact the same error occurs.
Here is the code how i switch the views:
// 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)
}
Update #2: The Apps crashes on line controller.dismissViewControllerAnimated(true, completion: nil)