我是Swift的新手,我正在创建一个程序,我需要通过代码使用segue。我确保标识符是正确的,我在正确的视图控制器中。我测试看按钮是否是问题,但事实并非如此。这是代码和错误:
@IBAction func doneButtonPressed(_ sender: UIButton) {
firstName = firstNameField.text!
lastName = lastNameField.text!
email = emailField.text!
let contact = Contact(first: firstName, last: lastName, email: email)
storageContacts.append(contact)
self.performSegue(withIdentifier: "Done", sender: sender)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
let destinationvc = segue.destination
if let contactController = destinationvc as? ContactsTableViewController{
if segue.identifier != nil{
contactController.contacts = storageContacts
}
}
}
错误(准备,更改,按下是打印语句):
preparing
2016-12-09 15:07:23.337754 Contacts[11194:961012] [MC] System group container for systemgroup.com.apple.configurationprofiles path is /Users/nick/Library/Developer/CoreSimulator/Devices/7A8982FC-6CA4-4DB1-AA80-C58E83CDF7E0/data/Containers/Shared/SystemGroup/systemgroup.com.apple.configurationprofiles
2016-12-09 15:07:23.339582 Contacts[11194:961012] [MC] Reading from private effective user settings.
changed
changed
changed
pressed
preparing
2016-12-09 15:07:29.354 Contacts[11194:961012] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Contacts.ContactTableViewCell 0x7fdf11820600> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key fullName.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000111ef734b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010f20b21e objc_exception_throw + 48
2 CoreFoundation 0x0000000111ef7299 -[NSException raise] + 9
3 Foundation 0x000000010ed1b26f -[NSObject(NSKeyValueCoding) setValue:forKey:] + 291
4 UIKit 0x000000010f79e80d -[UIView(CALayerDelegate) setValue:forKey:] + 173
5 UIKit 0x000000010fae879e -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x0000000111e9c590 -[NSArray makeObjectsPerformSelector:] + 256
7 UIKit 0x000000010fae7122 -[UINib instantiateWithOwner:options:] + 1867
8 UIKit 0x000000010f833df4 -[UITableView _dequeueReusableViewOfType:withIdentifier:] + 399
9 UIKit 0x000000010f8342ec -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:] + 71
10 Contacts 0x000000010ec1b546 _TFC8Contacts27ContactsTableViewController9tableViewfTCSo11UITableView12cellForRowAtV10Foundation9IndexPath_CSo15UITableViewCell + 150
11 Contacts 0x000000010ec1b7c7 _TToFC8Contacts27ContactsTableViewController9tableViewfTCSo11UITableView12cellForRowAtV10Foundation9IndexPath_CSo15UITableViewCell + 87
12 UIKit 0x000000010f8477b5 -[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 757
13 UIKit 0x000000010f847a13 -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 74
14 UIKit 0x000000010f81b47d -[UITableView _updateVisibleCellsNow:isRecursive:] + 3295
15 UIKit 0x000000010f850d95 -[UITableView _performWithCachedTraitCollection:] + 110
16 UIKit 0x000000010f8375ef -[UITableView layoutSubviews] + 222
17 UIKit 0x000000010f79ef50 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1237
18 QuartzCore 0x0000000114cadcc4 -[CALayer layoutSublayers] + 146
19 QuartzCore 0x0000000114ca1788 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
20 QuartzCore 0x0000000114ca1606 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
21 QuartzCore 0x0000000114c2f680 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 280
22 QuartzCore 0x0000000114c5c767 _ZN2CA11Transaction6commitEv + 475
23 QuartzCore 0x0000000114c5d0d7 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 113
24 CoreFoundation 0x0000000111e9be17 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
25 CoreFoundation 0x0000000111e9bd87 __CFRunLoopDoObservers + 391
26 CoreFoundation 0x0000000111e80b9e __CFRunLoopRun + 1198
27 CoreFoundation 0x0000000111e80494 CFRunLoopRunSpecific + 420
28 GraphicsServices 0x0000000113daca6f GSEventRunModal + 161
29 UIKit 0x000000010f6da964 UIApplicationMain + 159
30 Contacts 0x000000010ec20cdf main + 111
31 libdyld.dylib 0x0000000112e2468d start + 1
32 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException