2015-09-01 71 views
0

只要我通过“控件拖到”我的两个文本字段连接到我的代码作为出口增加的UITextField到代码时,我不能让到视图它只是退出给我信号SIGABRT

线程1:信号SIGABRT

的应用程序运行,但只要我打开网页到这些文本框是我的应用程序失败。我有完全相同的代码中的另一个应用程序完全相同的设置,但我没有得到错误我的代码如下:

import UIKit 
import MessageUI 

class ContactPage: UIViewController, MFMailComposeViewControllerDelegate { 

    override func prefersStatusBarHidden() -> Bool { 
     return true; 
    } 

    var alert = UIAlertView() 

    @IBOutlet var Name: UITextField! 
    @IBOutlet var Message: UITextField! 

    override func viewDidLoad() { 
     super.viewDidLoad() 
     // Do any additional setup after loading the view, typically from a nib. 
    } 
    override func didReceiveMemoryWarning() { 
     super.didReceiveMemoryWarning() 
     // Dispose of any resources that can be recreated. 
    } 

    @IBAction func MakeCall(sender: AnyObject) { 
     self.alert.title = "Calling Now..." 
     self.alert.message = "You call will comence soon." 
     self.alert.addButtonWithTitle("Ok") 
     self.alert.show() 
     let url:NSURL = NSURL(string: "tel://0394172817")! 
     UIApplication.sharedApplication().openURL(url) 
    } 

    @IBAction func email(sender: AnyObject) { 

     if (MFMailComposeViewController.canSendMail()) { 

      let SubjectText = "" 
      let MessageBody = "" 
      let toRecipients = ["[email protected]"] 

      let mc: MFMailComposeViewController = MFMailComposeViewController() 
      mc.mailComposeDelegate = self 
      mc.setSubject(SubjectText) 
      mc.setMessageBody(MessageBody, isHTML: false) 
      mc.setToRecipients(toRecipients) 

      self.presentViewController(mc, animated: true, completion: nil) 

     } else { 
      print("No email account found") 
     } 
    } 

    @IBAction func Submit(sender: AnyObject) { 

     if (MFMailComposeViewController.canSendMail()) { 

      let SubjectText = Name 
      let MessageBody = Message 
      let toRecipients = ["[email protected]"] 

      let mc: MFMailComposeViewController = MFMailComposeViewController() 
      mc.mailComposeDelegate = self 
      mc.setSubject(SubjectText.text!) 
      mc.setMessageBody(MessageBody.text!, isHTML: false) 
      mc.setToRecipients(toRecipients) 

      self.alert.title = "Registration Form" 
      self.alert.message = "On this screen please press send." 
      self.alert.addButtonWithTitle("Ok") 
      self.alert.show() 

      self.presentViewController(mc, animated: true, completion: nil) 

     } else { 
      print("No email account found") 
     } 
    } 

    func mailComposeController(controller: MFMailComposeViewController, didFinishWithResult result: MFMailComposeResult, error: NSError?) { 

     switch result.rawValue { 

      case MFMailComposeResultCancelled.rawValue: 
       print("Mail Cancelled") 
      case MFMailComposeResultSaved.rawValue: 
       print("Mail Saved") 
      case MFMailComposeResultSent.rawValue: 
       print("Mail Sent") 
       self.alert.title = "Contact Form" 
       self.alert.message = "Your form has been sent." 
       self.alert.addButtonWithTitle("Ok") 
       self.alert.show() 
      case MFMailComposeResultFailed.rawValue: 
       print("Mail Failed") 
       self.alert.title = "Contact Form" 
       self.alert.message = "Your form failed to be sent. Please check your internet connection and try again" 
       self.alert.addButtonWithTitle("Ok") 
       self.alert.show() 
      default: 
       break 
     } 

     self.dismissViewControllerAnimated(false, completion: nil) 

     self.performSegueWithIdentifier("ShowHome", sender: self) 
    } 
} 

我还会将错误代码:

2015-09-01 12:02:43.976 App Name[91111:2205337] Unknown class ContactPage in Interface Builder file. 
2015-09-01 12:02:44.078 App Name[91111:2205337] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x7ff781d0a110> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Message.' 
*** First throw call stack: 
(
    0 CoreFoundation      0x00000001051a99b5 __exceptionPreprocess + 165 
    1 libobjc.A.dylib      0x00000001071ffdeb objc_exception_throw + 48 
    2 CoreFoundation      0x00000001051a95f9 -[NSException raise] + 9 
    3 Foundation       0x0000000105573fdb -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288 
    4 UIKit        0x0000000105f9c418 -[UIViewController setValue:forKey:] + 88 
    5 UIKit        0x00000001061af2c7 -[UIRuntimeOutletConnection connect] + 109 
    6 CoreFoundation      0x00000001050ea590 -[NSArray makeObjectsPerformSelector:] + 224 
    7 UIKit        0x00000001061adcaa -[UINib instantiateWithOwner:options:] + 1864 
    8 UIKit        0x0000000105fa2df4 -[UIViewController _loadViewFromNibNamed:bundle:] + 381 
    9 UIKit        0x0000000105fa3720 -[UIViewController loadView] + 178 
    10 UIKit        0x0000000105fa3a22 -[UIViewController loadViewIfRequired] + 138 
    11 UIKit        0x0000000105fa4054 -[UIViewController view] + 27 
    12 UIKit        0x00000001066d36d2 -[_UIFullscreenPresentationController _setPresentedViewController:] + 87 
    13 UIKit        0x0000000105f74a4e -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 133 
    14 UIKit        0x0000000105fb65ca -[UIViewController _presentViewController:withAnimationController:completion:] + 3736 
    15 UIKit        0x0000000105fb94b3 -[UIViewController presentViewController:animated:completion:] + 343 
    16 UIKit        0x00000001064eee8b __67-[UIStoryboardModalSegueTemplate newDefaultPerformHandlerForSegue:]_block_invoke + 243 
    17 UIKit        0x00000001064dd523 -[UIStoryboardSegueTemplate _perform:] + 449 
    18 UIKit        0x00000001064dd5ea -[UIStoryboardSegueTemplate perform:] + 156 
    19 UIKit        0x0000000105e1f522 -[UIApplication sendAction:to:from:forEvent:] + 92 
    20 UIKit        0x0000000105f7ec06 -[UIControl sendAction:to:forEvent:] + 67 
    21 UIKit        0x0000000105f7eeac -[UIControl _sendActionsForEvents:withEvent:] + 273 
    22 UIKit        0x0000000105f7e008 -[UIControl touchesEnded:withEvent:] + 601 
    23 UIKit        0x0000000105e8715f -[UIWindow _sendTouchesForEvent:] + 835 
    24 UIKit        0x0000000105e87d4d -[UIWindow sendEvent:] + 865 
    25 UIKit        0x0000000105e3c2ae -[UIApplication sendEvent:] + 263 
    26 UIKit        0x0000000105e1836c _UIApplicationHandleEventQueue + 6693 
    27 CoreFoundation      0x00000001050d5b21 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 
    28 CoreFoundation      0x00000001050cba4c __CFRunLoopDoSources0 + 556 
    29 CoreFoundation      0x00000001050caf03 __CFRunLoopRun + 867 
    30 CoreFoundation      0x00000001050ca918 CFRunLoopRunSpecific + 488 
    31 GraphicsServices     0x000000010acdcad2 GSEventRunModal + 161 
    32 UIKit        0x0000000105e1d99e UIApplicationMain + 171 
    33 App Name      0x0000000104fa749d main + 109 
    34 libdyld.dylib      0x0000000107d6492d start + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
(lldb) 

如果可能的话解释尽可能详细地说,我对swift和Xcode非常陌生,并且对于如何运行Xcode有点不确定。提前致谢。

回答

0

如果在查看ContactPage文件时查看实用程序导航器,是否正确选择了目标成员?

Screenshot of Xcode Utilities Navigator

如果不选择目标会员,编译的二进制将不包括ContactPage。

如果目标成员身份选择正确,请在Interface Builder中仔细检查Module是否指向您的应用程序,而不是您的类名称下方的“无”。

Interface Builder Utilities Navigator

最后,用干净CMD + K你的项目。这也可以解决几个中断的依赖关系。