I'm kind of new to Swift, and I was creating a program where I needed to use a segue through code. I made sure the identifier was correct, and I am in the right view controller. I tested to see if the button was the problem, and it wasn't. Here is the code and the error:
#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
}
}
}
Error(preparing, changed, pressed are print statements):
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
Related
I have three view controllers in total. I pressed Cntrl on the first view controller and created a segue to the second one on the bottom right (haven't tested the top right one yet). Storyboard is below:
The description of the second segue from the bottom is:
I have placed the segues inside an the IBAction for the button at the bottom of the first view controller. The code is as below:
class ViewController: UIViewController {
private lazy var app = ProjectApp()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
#IBAction func start_test(_ sender: Any) {
if app.is_facial_analysis_completed() {
DispatchQueue.main.async() {
self.performSegue(withIdentifier: "home_to_quiz", sender: self)
}
} else {
DispatchQueue.main.async() {
self.performSegue(withIdentifier: "home_to_vision", sender: self)
}
}
}
}
Not really sure as to why I am getting this error:
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Here is the code for the quiz view class:
import UIKit
class QuizViewController: UIViewController {
#IBOutlet var QuizView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
}
}
Here is a screenshot of the view controller of the quizViewController:
The Full ERROR
2019-11-20 02:02:34.141705+0400 XXX[47921:9768662] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x7fd98a7088b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key QuizView.'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff23baa1ee __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff50864b20 objc_exception_throw + 48
2 CoreFoundation 0x00007fff23ba9db9 -[NSException raise] + 9
3 Foundation 0x00007fff2563e130 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 325
4 UIKitCore 0x00007fff46f008e9 -[UIViewController setValue:forKey:] + 87
5 UIKitCore 0x00007fff471ec3fa -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x00007fff23b96212 -[NSArray makeObjectsPerformSelector:] + 242
7 UIKitCore 0x00007fff471e95a2 -[UINib instantiateWithOwner:options:] + 2190
8 UIKitCore 0x00007fff46f07b3b -[UIViewController _loadViewFromNibNamed:bundle:] + 395
9 UIKitCore 0x00007fff46f08660 -[UIViewController loadView] + 177
10 UIKitCore 0x00007fff46f0895f -[UIViewController loadViewIfRequired] + 172
11 UIKitCore 0x00007fff46f0910c -[UIViewController view] + 27
12 UIKitCore 0x00007fff46f2038e -[UIViewController _setPresentationController:] + 100
13 UIKitCore 0x00007fff46f18b9a -[UIViewController _presentViewController:modalSourceViewController:presentationController:animationController:interactionController:completion:] + 1256
14 UIKitCore 0x00007fff46f1a602 -[UIViewController _presentViewController:withAnimationController:completion:] + 4325
15 UIKitCore 0x00007fff46f1ce7b __63-[UIViewController _presentViewController:animated:completion:]_block_invoke + 98
16 UIKitCore 0x00007fff46f1d393 -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 511
17 UIKitCore 0x00007fff46f1cdd9 -[UIViewController _presentViewController:animated:completion:] + 187
18 UIKitCore 0x00007fff46f1d040 -[UIViewController presentViewController:animated:completion:] + 150
19 UIKitCore 0x00007fff46f2131f -[UIViewController _showViewController:withAction:sender:] + 272
20 UIKitCore 0x00007fff476d69b7 __66-[UIStoryboardShowSegueTemplate newDefaultPerformHandlerForSegue:]_block_invoke + 134
21 UIKitCore 0x00007fff476dc410 -[UIStoryboardSegueTemplate _performWithDestinationViewController:sender:] + 276
22 UIKitCore 0x00007fff476dc2ce -[UIStoryboardSegueTemplate _perform:] + 82
23 UIKitCore 0x00007fff46f0be3b -[UIViewController performSegueWithIdentifier:sender:] + 99
24 XXX 0x000000010d49b896 $s3XXX14ViewControllerC19pulse_permute_segueyyFyycfU_ + 118
25 XXX 0x000000010d494c7d $sIeg_IeyB_TR + 45
26 libdispatch.dylib 0x000000010d954df8 _dispatch_call_block_and_release + 12
27 libdispatch.dylib 0x000000010d955d6c _dispatch_client_callout + 8
28 libdispatch.dylib 0x000000010d963e24 _dispatch_main_queue_callback_4CF + 1500
29 CoreFoundation 0x00007fff23b0ce49 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
30 CoreFoundation 0x00007fff23b07aa9 __CFRunLoopRun + 2329
31 CoreFoundation 0x00007fff23b06e66 CFRunLoopRunSpecific + 438
32 GraphicsServices 0x00007fff38346bb0 GSEventRunModal + 65
33 UIKitCore 0x00007fff47578dd0 UIApplicationMain + 1621
34 XXX 0x000000010d4a724b main + 75
35 libdyld.dylib 0x00007fff516ecd29 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Maybe you need to add UINavigationViewController like Initial View Controller?
Or you need override this method and setup some required data on second controller?
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if (segue.identifier == "home_to_quiz") {
let dectinationView = segue.destination as! YourCustomViewController
dectinationView.dataContainer = self.dataContainer
}
}
Addition
Here are a few moments where something could go wrong:
Class of your UIViewController must be Inherit From Target
Try to delete your Selector (home_to_quiz:) in Storyboard. Do you implement a selector method inside a controller?
I have been developing framework, I have used tab menu using carbonKit cocoapods, Now i'm trying to navigate UIVIewController xib.
When UITabBarController loaded the carbonkit menu default tab menu will be called.
Here is the code used for load xib UIViewcontroller
public func carbonTabSwipeNavigation(_ carbonTabSwipeNavigation: CarbonTabSwipeNavigation, viewControllerAt index: UInt) -> UIViewController {
print("called carbonkit")
print("carbon kit index 0 called")
return (UINib(nibName: "FirstViewController", bundle: Bundle(for: FirstViewController.self)).instantiate(withOwner: nil, options: nil).first as? FirstViewController)!
}
Here is the console output:
Called tab
called carbonkit
carbon kit index 0 called
2019-11-12 22:13:02.350434+0530 A8FlowSampleApp[41059:1971714] ***
Terminating app due to uncaught exception 'NSUnknownKeyException',
reason: '[<NSObject 0x600000b1c8b0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key view.'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff23c4f02e __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff50b97b20 objc_exception_throw + 48
2 CoreFoundation 0x00007fff23c4ebf9 -[NSException raise] + 9
3 Foundation 0x00007fff256f2ef3 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 325
4 UIKitCore 0x00007fff474b9a52 -[UIRuntimeOutletConnection connect] + 109
5 CoreFoundation 0x00007fff23c3b052 -[NSArray makeObjectsPerformSelector:] + 242
6 UIKitCore 0x00007fff474b6bfa -[UINib instantiateWithOwner:options:] + 2190
7 A8Flow 0x0000000104db51d8 $s6A8Flow6MyTaskC24carbonTabSwipeNavigation_16viewControllerAtSo06UIViewJ0CSo06CarbonfgH0C_SutF + 1016
8 A8Flow 0x0000000104db546d $s6A8Flow6MyTaskC24carbonTabSwipeNavigation_16viewControllerAtSo06UIViewJ0CSo06CarbonfgH0C_SutFTo + 77
9 CarbonKit 0x00000001048c1d31 -[CarbonTabSwipeNavigation viewControllerAtIndex:] + 593
10 CarbonKit 0x00000001048c18fb -[CarbonTabSwipeNavigation loadFirstViewController] + 411
11 CarbonKit 0x00000001048bc90e -[CarbonTabSwipeNavigation initWithItems:delegate:] + 350
12 A8Flow 0x0000000104db69f2 $sSo24CarbonTabSwipeNavigationC5items8delegateABSayypGSg_yptcfcTO + 242
13 A8Flow 0x0000000104db4bc2 $sSo24CarbonTabSwipeNavigationC5items8delegateABSayypGSg_yptcfC + 50
14 A8Flow 0x0000000104db40ba $s6A8Flow6MyTaskC11viewDidLoadyyF + 378
15 A8Flow 0x0000000104db4dcb $s6A8Flow6MyTaskC11viewDidLoadyyFTo + 43
16 UIKitCore 0x00007fff471cdb45 -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 83
17 UIKitCore 0x00007fff471d2a9e -[UIViewController loadViewIfRequired] + 1084
18 UIKitCore 0x00007fff47136b8c -[UINavigationController _updateScrollViewFromViewController:toViewController:] + 160
19 UIKitCore 0x00007fff47136e8c -[UINavigationController _startTransition:fromViewController:toViewController:] + 140
20 UIKitCore 0x00007fff47137d56 -[UINavigationController _startDeferredTransitionIfNeeded:] + 868
21 UIKitCore 0x00007fff471390c1 -[UINavigationController __viewWillLayoutSubviews] + 150
22 UIKitCore 0x00007fff47119ef7 -[UILayoutContainerView layoutSubviews] + 217
23 UIKitCore 0x00007fff47d34cfd -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 2478
24 QuartzCore 0x00007fff2b138d41 -[CALayer layoutSublayers] + 255
25 QuartzCore 0x00007fff2b13ef33 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 517
26 QuartzCore 0x00007fff2b14a86a _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 80
27 QuartzCore 0x00007fff2b0917c8 _ZN2CA7Context18commit_transactionEPNS_11TransactionEd + 324
28 QuartzCore 0x00007fff2b0c6ad1 _ZN2CA11Transaction6commitEv + 643
29 UIKitCore 0x00007fff47867481 __34-[UIApplication _firstCommitBlock]_block_invoke_2 + 81
30 CoreFoundation 0x00007fff23bb204c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
31 CoreFoundation 0x00007fff23bb17b8 __CFRunLoopDoBlocks + 312
32 CoreFoundation 0x00007fff23bac644
__CFRunLoopRun + 1284
33 CoreFoundation 0x00007fff23babe16
CFRunLoopRunSpecific + 438
34 GraphicsServices 0x00007fff38438bb0
GSEventRunModal + 65
35 UIKitCore 0x00007fff4784fb68
UIApplicationMain + 1621
36 A8FlowSampleApp 0x000000010458a6bb main + 75
37 libdyld.dylib 0x00007fff51a1dc25 start + 1
38 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type
NSException
(lldb)
Any help much appreciated pls.. tried lot ways to achieve it but could not make it.
Fixed myself
func firstView() -> UIViewController {
let cont = FirstViewController()
self.tabContView?.addChild(cont)
self.tabContView?.view.addSubview(cont.view)
cont.didMove(toParent: tabContView)
return cont
}
public func carbonTabSwipeNavigation(_ carbonTabSwipeNavigation: CarbonTabSwipeNavigation, viewControllerAt index: UInt) -> UIViewController {
print("called carbonkit")
print("carbon kit index 0 called")
return firstView()
}
override func viewDidLoad() {
super.viewDidLoad()
**detailLabel.text = game**
}
#IBAction func selectedGame(segue:UIStoryboardSegue) {
if let gamePickerViewController = segue.sourceViewController as? GamePickerViewController,
selectedGame = gamePickerViewController.selectedGame {
**detailLabel.text = selectedGame**
game = selectedGame
}
}
Swift Compile Error 'text' is unavailable: APIs deprecated as of iOS 7 and earlier are unavailable in Swift
Edit :
#IBOutlet weak var detailLabel: UILabel!
But,
init PlayerDetailsViewController
2015-09-01 14:14:45.050 Ratings[3594:145699] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Ratings.PlayerDetailsViewController 0x7ff6c3d42e80> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key detailLabelCurrent.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010483dc65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001063a8bb7 objc_exception_throw + 45
2 CoreFoundation 0x000000010483d8a9 -[NSException raise] + 9
3 Foundation 0x0000000104c5bb53 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
4 CoreFoundation 0x0000000104785d50 -[NSArray makeObjectsPerformSelector:] + 224
5 UIKit 0x00000001053b44eb -[UINib instantiateWithOwner:options:] + 1506
6 UIKit 0x000000010520c6d8 -[UIViewController _loadViewFromNibNamed:bundle:] + 242
7 UIKit 0x000000010520ccc8 -[UIViewController loadView] + 109
8 UIKit 0x00000001053d0db8 -[UITableViewController loadView] + 76
9 UIKit 0x000000010520cf39 -[UIViewController loadViewIfRequired] + 75
10 UIKit 0x000000010520d3ce -[UIViewController view] + 27
11 UIKit 0x0000000105246d3b -[UINavigationController preferredContentSize] + 149
12 UIKit 0x00000001051eceee -[UIPresentationController preferredContentSizeDidChangeForChildContentContainer:] + 101
13 UIKit 0x00000001051ea33d __56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 122
14 UIKit 0x00000001051005ec _applyBlockToCFArrayCopiedToStack + 314
15 UIKit 0x0000000105100466 _afterCACommitHandler + 533
16 CoreFoundation 0x0000000104770ca7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
17 CoreFoundation 0x0000000104770c00 __CFRunLoopDoObservers + 368
18 CoreFoundation 0x0000000104766a33 __CFRunLoopRun + 1123
19 CoreFoundation 0x0000000104766366 CFRunLoopRunSpecific + 470
20 GraphicsServices 0x0000000108811a3e GSEventRunModal + 161
21 UIKit 0x00000001050dc8c0 UIApplicationMain + 1282
22 Ratings 0x000000010461b357 main + 135
23 libdyld.dylib 0x0000000106ade145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
I have encountered with these situation, how can i fix these lines to prove all of iOS versions?
I have a Swift project and am trying to use JSQMessagesViewController within it. I have used cocoapods to install the framework and am importing it using a swift import statement.
import JSQMessagesViewController
Up to this point there are no errors and everything compiles without warning. However when I try to push a new instance onto a navigation controller the app crashes.
func openConversation(userId: Int) {
let messageViewController = JSQMessagesViewController();
self.navigationController?.pushViewController(messageViewController, animated: true)
}
The second line of the method causes the crash and the error message is.
2015-08-03 21:44:17.229 [4856:64097] *** Assertion failure in -[JSQMessagesViewController viewWillAppear:], /[my file path]/Pods/JSQMessagesViewController/JSQMessagesViewController/Controllers/JSQMessagesViewController.m:223
2015-08-03 21:44:17.232 [4856:64097] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: self.senderId != nil'
*** First throw call stack:
(
0 CoreFoundation 0x00000001067e3c65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000108590bb7 objc_exception_throw + 45
2 CoreFoundation 0x00000001067e3aca +[NSException raise:format:arguments:] + 106
3 Foundation 0x0000000106ec298f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4 JSQMessagesViewController 0x00000001060e9055 -[JSQMessagesViewController viewWillAppear:] + 277
5 UIKit 0x00000001073f8f61 -[UIViewController _setViewAppearState:isAnimating:] + 487
6 UIKit 0x000000010741a355 -[UINavigationController _startCustomTransition:] + 887
7 UIKit 0x000000010742637f -[UINavigationController _startDeferredTransitionIfNeeded:] + 386
8 UIKit 0x0000000107426ece -[UINavigationController __viewWillLayoutSubviews] + 43
9 UIKit 0x00000001075716d5 -[UILayoutContainerView layoutSubviews] + 202
10 UIKit 0x00000001073449eb -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 536
11 QuartzCore 0x0000000108f5ded2 -[CALayer layoutSublayers] + 146
12 QuartzCore 0x0000000108f526e6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
13 QuartzCore 0x0000000108f52556 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
14 QuartzCore 0x0000000108ebe86e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242
15 QuartzCore 0x0000000108ebfa22 _ZN2CA11Transaction6commitEv + 462
16 QuartzCore 0x0000000108ec00d3 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 89
17 CoreFoundation 0x0000000106716ca7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
18 CoreFoundation 0x0000000106716c00 __CFRunLoopDoObservers + 368
19 CoreFoundation 0x000000010670ca33 __CFRunLoopRun + 1123
20 CoreFoundation 0x000000010670c366 CFRunLoopRunSpecific + 470
21 GraphicsServices 0x000000010b148a3e GSEventRunModal + 161
22 UIKit 0x00000001072c48c0 UIApplicationMain + 1282
23 Startana 0x0000000105fa2807 main + 135
24 libdyld.dylib 0x0000000109306145 start + 1
25 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
After searching online I cant seem to find any information about what causes this issue.
I’m glad to hear it solved your issue!
The JSQMessagesViewController have two asset parameters, the senderId and the senderDisplayName.
So you must set your senderId and display name.
In your current controller which is inherited by JSQMessagesViewController
you will need to do couple of things first add setup function
func setup() {
self.senderId = "1234"
self.senderDisplayName = "TEST"
}
and latter invoke that function from
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.setup()
}
I have a app in swift where I'm just trying to pass a string from one ViewController to another. After the segue, I see the second viewController on top of the first, the data is passed, and I get the following exception:
2014-07-11 10:58:17.078 Flipper[8967:377257] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_TtC7Flipper19FirstViewController textField:]: unrecognized selector sent to instance 0x7fba2351eda0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010c805055 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010e528a1c objc_exception_throw + 45
2 CoreFoundation 0x000000010c80bf1d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x000000010c764dbc ___forwarding___ + 988
4 CoreFoundation 0x000000010c764958 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010d2ed196 -[UIApplication sendAction:to:from:forEvent:] + 75
6 UIKit 0x000000010d3f1c80 -[UIControl _sendActionsForEvents:withEvent:] + 467
7 UIKit 0x000000010d9fbb86 -[UITextField _resignFirstResponder] + 256
8 UIKit 0x000000010d45cbff -[UIResponder resignFirstResponder] + 117
9 UIKit 0x000000010d9fb98f -[UITextField resignFirstResponder] + 114
10 UIKit 0x000000010d355722 -[UIView(Hierarchy) _removeFirstResponderFromSubtree] + 161
11 UIKit 0x000000010d355bdd __UIViewWillBeRemovedFromSuperview + 76
12 UIKit 0x000000010d35594c -[UIView(Hierarchy) removeFromSuperview] + 91
13 UIKit 0x000000010d3ef12c __71-[UIPresentationController _initViewHierarchyForPresentationSuperview:]_block_invoke478 + 785
14 UIKit 0x000000010d3eb7bd -[UIPresentationController transitionDidFinish:] + 87
15 UIKit 0x000000010d3edd8e __56-[UIPresentationController runTransitionForCurrentState]_block_invoke_2 + 133
16 UIKit 0x000000010da1d123 -[_UIViewControllerTransitionContext completeTransition:] + 110
17 UIKit 0x000000010d3e8ea3 -[UITransitionView _didCompleteTransition:] + 1120
18 UIKit 0x000000010d34542a -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 209
19 UIKit 0x000000010d345760 -[UIViewAnimationState animationDidStop:finished:] + 76
20 QuartzCore 0x000000010d176f9e _ZN2CA5Layer23run_animation_callbacksEPv + 308
21 libdispatch.dylib 0x000000010ea64d64 _dispatch_client_callout + 8
22 libdispatch.dylib 0x000000010ea50f82 _dispatch_main_queue_callback_4CF + 941
23 CoreFoundation 0x000000010c76dae9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
24 CoreFoundation 0x000000010c73046b __CFRunLoopRun + 2043
25 CoreFoundation 0x000000010c72fa06 CFRunLoopRunSpecific + 470
26 GraphicsServices 0x00000001103b9abf GSEventRunModal + 161
27 UIKit 0x000000010d2ebcf8 UIApplicationMain + 1282
28 Flipper 0x000000010c37737d top_level_code + 77
29 Flipper 0x000000010c3773ba main + 42
30 libdyld.dylib 0x000000010ea99145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
My VC1 code is:
class FirstViewController: UIViewController {
#IBOutlet var textField: UITextField
var myVariable:String!
override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
if (segue.identifier == "P1ToP2") {
var svc = segue!.destinationViewController as SecondViewController;
myVariable = textField.text
svc.myVariable = myVariable
}
}
}
My VC2 code is:
class SecondViewController: UIViewController {
#IBOutlet var labelTwo: UILabel
var myVariable:String!
override func viewDidLoad() {
super.viewDidLoad()
labelTwo.text = myVariable
}
I'm using a Storyboard where VC1 has a Button that invokes a Show (push) segue called P1ToP2
Any ideas what I'm doing wrong? Thanks
As your crash says:
reason: '-[_TtC7Flipper19FirstViewController textField:]: unrecognized selector sent to instance
and you have not mentioned that the crash occurs on clicking the button.
My guess is try remove the space between textField: and UITextField.
I guess the problem is there, not in passing the string.