通过“ Control Drag”将我的2个文本字段连接到我的代码后,我便无法进入视图,因为它退出了,给了我
线程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 = ["test@test.com"]
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 = ["test@test.com"]
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还是陌生的,对所有的运行方式还是不太确定。提前致谢。
最佳答案
如果在查看ContactPage文件的同时查看实用程序导航器,是否正确选择了目标成员身份?
如果未选择“目标成员身份”,则编译后的二进制文件将不包含ContactPage。
如果正确选择了“目标成员身份”,请在Interface Builder中,再次检查“模块”是否指向您的应用,而不是您的类名称下是否“无”。
最后,使用cmd + k清理您的项目。这也可以解决几个破碎的依赖关系。