terminating with uncaught exception of type NSException (lldb) - swift

I got an error,
terminating with uncaught exception of type NSException
(lldb) .
Error is
error
Traceback is
2017-06-11 22:10:04.009 Kenshin_Swift[6073:541383] Unknown class PhotoController in Interface Builder file.
2017-06-11 22:10:04.120 Kenshin_Swift[6073:541383] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x7fe830f06900> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key PhotoSelect.'
*** First throw call stack:
(
0 CoreFoundation 0x00000001068efd4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010635821e objc_exception_throw + 48
2 CoreFoundation 0x00000001068efc99 -[NSException raise] + 9
3 Foundation 0x0000000105c919df -[NSObject(NSKeyValueCoding) setValue:forKey:] + 291
4 UIKit 0x0000000106eae293 -[UIViewController setValue:forKey:] + 88
5 UIKit 0x000000010712279e -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x00000001068949e0 -[NSArray makeObjectsPerformSelector:] + 256
7 UIKit 0x0000000107121122 -[UINib instantiateWithOwner:options:] + 1867
8 UIKit 0x0000000106eb49c5 -[UIViewController _loadViewFromNibNamed:bundle:] + 386
9 UIKit 0x0000000106eb52e7 -[UIViewController loadView] + 177
10 UIKit 0x0000000106eb561c -[UIViewController loadViewIfRequired] + 201
11 UIKit 0x0000000106eb5e70 -[UIViewController view] + 27
12 UIKit 0x0000000106f144f3 -[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:] + 483
13 UIKit 0x0000000106f13935 -[UITabBarController transitionFromViewController:toViewController:] + 59
14 UIKit 0x0000000106f0f7f6 -[UITabBarController _setSelectedViewController:] + 365
15 UIKit 0x0000000106f0f678 -[UITabBarController setSelectedViewController:] + 234
16 UIKit 0x0000000106dcd239 +[UIView(Animation) performWithoutAnimation:] + 90
17 UIKit 0x0000000106f09c14 -[UITabBarController _selectDefaultViewControllerIfNecessaryWithAppearanceTransitions:] + 354
18 UIKit 0x0000000106f0ad8e -[UITabBarController viewWillAppear:] + 206
19 UIKit 0x0000000106ebb96f -[UIViewController _setViewAppearState:isAnimating:] + 692
20 UIKit 0x0000000106ebc07f -[UIViewController __viewWillAppear:] + 147
21 UIKit 0x0000000106ebd873 -[UIViewController viewWillMoveToWindow:] + 507
22 UIKit 0x0000000106dc3a87 -[UIView(Hierarchy) _willMoveToWindow:withAncestorView:] + 621
23 UIKit 0x0000000106dd485b -[UIView(Internal) _addSubview:positioned:relativeTo:] + 451
24 UIKit 0x0000000106dc30d7 -[UIView(Hierarchy) addSubview:] + 838
25 UIKit 0x0000000106d7f7bf -[UIWindow addRootViewControllerViewIfPossible] + 849
26 UIKit 0x0000000106d7fc06 -[UIWindow _setHidden:forced:] + 293
27 UIKit 0x0000000106d93519 -[UIWindow makeKeyAndVisible] + 42
28 UIKit 0x0000000106d0bf8d -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4818
29 UIKit 0x0000000106d120ed -[UIApplication _runWithMainScene:transitionContext:completion:] + 1731
30 UIKit 0x0000000106d0f26d -[UIApplication workspaceDidEndTransaction:] + 188
31 FrontBoardServices 0x000000010a55d6cb __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
32 FrontBoardServices 0x000000010a55d544 -[FBSSerialQueue _performNext] + 189
33 FrontBoardServices 0x000000010a55d8cd -[FBSSerialQueue _performNextFromRunLoopSource] + 45
34 CoreFoundation 0x0000000106894761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
35 CoreFoundation 0x000000010687998c __CFRunLoopDoSources0 + 556
36 CoreFoundation 0x0000000106878e76 __CFRunLoopRun + 918
37 CoreFoundation 0x0000000106878884 CFRunLoopRunSpecific + 420
38 UIKit 0x0000000106d0daea -[UIApplication _run] + 434
39 UIKit 0x0000000106d13c68 UIApplicationMain + 159
40 Kenshin_Swift 0x0000000105b9f07f main + 111
41 libdyld.dylib 0x0000000109dc368d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
PhotoController is
import Foundation
import UIKit
class PhotoController:UIViewController,UINavigationControllerDelegate,UIImagePickerControllerDelegate{
#IBOutlet weak var myImageView: UIImageView!
#IBAction func PhotoSelect(_ sender: Any) {
}
#IBAction func PhotoSend(_ sender: Any) {
let myPickerController = UIImagePickerController()
myPickerController.delegate = self;
myPickerController.sourceType = UIImagePickerControllerSourceType.photoLibrary
self.present(myPickerController, animated: true, completion: nil)
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject])
{
myImageView.image = info[UIImagePickerControllerOriginalImage] as? UIImage
self.dismiss(animated: true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
//myImageUploadRequest()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Outlet is
outlet
I read why this error message happen. It said when "Outlet" is wrong,this error happen.But I do not know how to fix this.I saw outlet of PhotoSelect&PhotoSend has !,but I cannot understand this mean.What should I do?

The problem is the two outlets PhotoSelect and PhotoSend. You probably accidentally created these as #IBOutlet, deleted them and recreated them as #IBAction.
See how they have a ! next to them. This means that these outlets are no longer connected. So when you run you app, your storyboard cannot find those outlets in your view controller, so it crashes.
You need to remove those outlets by clicking the x.

Related

NSUnknownKeyException - Xcode

My program shows this problem. Can anybody tell me what's wrong?
"2016-08-26 17:21:00.548 SegundaTentativa[2347:203583] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<SegundaTentativa.ViewController 0x7f9749d188d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key imQuadro.'
*** First throw call stack:
(
0 CoreFoundation 0x000000010786dd85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000109611deb objc_exception_throw + 48
2 CoreFoundation 0x000000010786d9c9 -[NSException raise] + 9
3 Foundation 0x0000000107c3f19b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
4 UIKit 0x0000000108228d0c -[UIViewController setValue:forKey:] + 88
5 UIKit 0x000000010845f7fb -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x00000001077a7890 -[NSArray makeObjectsPerformSelector:] + 224
7 UIKit 0x000000010845e1de -[UINib instantiateWithOwner:options:] + 1864
8 UIKit 0x000000010822f8d6 -[UIViewController _loadViewFromNibNamed:bundle:] + 381
9 UIKit 0x0000000108230202 -[UIViewController loadView] + 178
10 UIKit 0x0000000108230560 -[UIViewController loadViewIfRequired] + 138
11 UIKit 0x0000000108230cd3 -[UIViewController view] + 27
12 UIKit 0x0000000108106fb4 -[UIWindow addRootViewControllerViewIfPossible] + 61
13 UIKit 0x000000010810769d -[UIWindow _setHidden:forced:] + 282
14 UIKit 0x0000000108119180 -[UIWindow makeKeyAndVisible] + 42
15 UIKit 0x000000010808ded9 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131
16 UIKit 0x0000000108094568 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1769
17 UIKit 0x0000000108091714 -[UIApplication workspaceDidEndTransaction:] + 188
18 FrontBoardServices 0x000000010b4a28c8 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
19 FrontBoardServices 0x000000010b4a2741 -[FBSSerialQueue _performNext] + 178
20 FrontBoardServices 0x000000010b4a2aca -[FBSSerialQueue _performNextFromRunLoopSource] + 45
21 CoreFoundation 0x0000000107793301 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
22 CoreFoundation 0x000000010778922c __CFRunLoopDoSources0 + 556
23 CoreFoundation 0x00000001077886e3 __CFRunLoopRun + 867
24 CoreFoundation 0x00000001077880f8 CFRunLoopRunSpecific + 488
25 UIKit 0x0000000108090f21 -[UIApplication _run] + 402
26 UIKit 0x0000000108095f09 UIApplicationMain + 171
27 SegundaTentativa 0x0000000107688432 main + 114
28 libdyld.dylib 0x000000010a0d592d start + 1
29 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) "
ViewController:
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var lbTexto: UILabel!
#IBOutlet weak var imgQuadro: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
lbTexto.text = "Que jogador de vôlei e?"
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func ChangeText(sender: AnyObject) {
lbTexto.text = "Ricardinho"
}
#IBAction func HiddenQuadro(sender: AnyObject) {
imgQuadro.hidden = true
}
/*#IBAction func TesteSimbora(sender: UIButton) {
lbText.text = "Ricardinho"
}
#IBAction func EscondeQuadro(sender: UIButton) {
imQuadro.hidden = true
}*/
}
Pay attention to error message:
Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<SegundaTentativa.ViewController 0x7f9749d188d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key imQuadro.'
Something tries to set non-existing imQuadro property of your view controller, and from stack trace mentioning outlets it probably happens when controller is loaded from storyboard/xib.
Most likely you have wrong outlet connection set in interface builder, that might happen if you initially created outlet with name imQuadro and then manually fixed it to imgQuadro only in your code.

Logout Button crash

I just implemented a logout button on my HeaderView sector. But somehow I keep getting this crash from Xcode.
I feel like this is somehow related to my func logoutBtnClicked(){***}.
so here is what my logoutBtnClicked() looks like:
//clicked logout
#IBAction func logout(sender: AnyObject) {
PFUser.logOutInBackgroundWithBlock { (error: NSError?) -> Void in
if error == nil {
NSUserDefaults.standardUserDefaults().removeObjectForKey("username")
NSUserDefaults.standardUserDefaults().synchronize()
let signin = self.storyboard?.instantiateViewControllerWithIdentifier("signinViewController") as! SigninViewController
let appDelegate: AppDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
appDelegate.window?.rootViewController = signin
}
}
}
2016-08-18 21:18:54.801 helloworld[2439:115160] -[helloworld.HomeViewController Logout:]: unrecognized selector sent to instance 0x78e38840
2016-08-18 21:18:54.829 helloworld[2439:115160] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[helloworld.HomeViewController Logout:]: unrecognized selector sent to instance 0x78e38840'
* First throw call stack:
(
0 CoreFoundation 0x018d1494 exceptionPreprocess + 180
1 libobjc.A.dylib 0x035e5e02 objc_exception_throw + 50
2 CoreFoundation 0x018db253 -[NSObject(NSObject) doesNotRecognizeSelector:] + 275
3 CoreFoundation 0x0181089d ___forwarding_ + 1037
4 CoreFoundation 0x0181046e _CF_forwarding_prep_0 + 14
5 libobjc.A.dylib 0x035fa0b5 -[NSObject performSelector:withObject:withObject:] + 84
6 UIKit 0x020c1e38 -[UIApplication sendAction:to:from:forEvent:] + 118
7 UIKit 0x025519da -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 179
8 libobjc.A.dylib 0x035fa0b5 -[NSObject performSelector:withObject:withObject:] + 84
9 UIKit 0x020c1e38 -[UIApplication sendAction:to:from:forEvent:] + 118
10 UIKit 0x020c1db7 -[UIApplication sendAction:toTarget:fromSender:forEvent:] + 64
11 UIKit 0x02265f3b -[UIControl sendAction:to:forEvent:] + 79
12 UIKit 0x022662d4 -[UIControl _sendActionsForEvents:withEvent:] + 433
13 UIKit 0x02266483 -[UIControl _sendActionsForEvents:withEvent:] + 864
14 UIKit 0x022652c1 -[UIControl touchesEnded:withEvent:] + 714
15 UIKit 0x0214252e -[UIWindow _sendTouchesForEvent:] + 1095
16 UIKit 0x021435cc -[UIWindow sendEvent:] + 1159
17 UIKit 0x020e4be8 -[UIApplication sendEvent:] + 266
18 UIKit 0x020b9769 _UIApplicationHandleEventQueue + 7795
19 CoreFoundation 0x017e3e5f CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 15
20 CoreFoundation 0x017d9aeb __CFRunLoopDoSources0 + 523
21 CoreFoundation 0x017d8f08 __CFRunLoopRun + 1032
22 CoreFoundation 0x017d8846 CFRunLoopRunSpecific + 470
23 CoreFoundation 0x017d865b CFRunLoopRunInMode + 123
24 GraphicsServices 0x05f27664 GSEventRunModal + 192
25 GraphicsServices 0x05f274a1 GSEventRun + 104
26 UIKit 0x020bfeb9 UIApplicationMain + 160
27 helloworld 0x0007a4e1 main + 145
28 libdyld.dylib 0x043bba25 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
The problem is that in the interface builder for HomeViewController, for button action you have set Logout and inside the class of HomeViewController it is declare as logout, action and property are case sensitive, so either change one of them will solve your crash.

How to fix Error: this class is not key value coding-compliant for the key tableView.' [duplicate]

This question already has answers here:
this class is not key value coding-compliant for the key view [duplicate]
(7 answers)
Closed 6 years ago.
I made an app with Table View and Segmented Control, and this is my first time. I'm using some code and some tutorials, but It's not working. When I run my app It's crashing and it's showing this Error in logs:
MyApplication[4928:336085] * Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[ setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key tableView.'
* First throw call stack:
(
0 CoreFoundation 0x000000010516fd85 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000105504deb objc_exception_throw + 48
2 CoreFoundation 0x000000010516f9c9 -[NSException raise] + 9
3 Foundation 0x000000010364e19b -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
4 UIKit 0x0000000103c37d0c -[UIViewController setValue:forKey:] + 88
5 UIKit 0x0000000103e6e7fb -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x00000001050a9890 -[NSArray makeObjectsPerformSelector:] + 224
7 UIKit 0x0000000103e6d1de -[UINib instantiateWithOwner:options:] + 1864
8 UIKit 0x0000000103c3e8d6 -[UIViewController _loadViewFromNibNamed:bundle:] + 381
9 UIKit 0x0000000103c3f202 -[UIViewController loadView] + 178
10 UIKit 0x0000000103c3f560 -[UIViewController loadViewIfRequired] + 138
11 UIKit 0x0000000103c3fcd3 -[UIViewController view] + 27
12 UIKit 0x000000010440b024 -[_UIFullscreenPresentationController _setPresentedViewController:] + 87
13 UIKit 0x0000000103c0f5ca -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 133
14 UIKit 0x0000000103c525bb -[UIViewController _presentViewController:withAnimationController:completion:] + 4002
15 UIKit 0x0000000103c5585c -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 489
16 UIKit 0x0000000103c5536b -[UIViewController presentViewController:animated:completion:] + 179
17 UIKit 0x00000001041feb8d __67-[UIStoryboardModalSegueTemplate newDefaultPerformHandlerForSegue:]_block_invoke + 243
18 UIKit 0x00000001041ec630 -[UIStoryboardSegueTemplate _performWithDestinationViewController:sender:] + 460
19 UIKit 0x00000001041ec433 -[UIStoryboardSegueTemplate _perform:] + 82
20 UIKit 0x00000001041ec6f7 -[UIStoryboardSegueTemplate perform:] + 156
21 UIKit 0x0000000103aa6a8d -[UIApplication sendAction:to:from:forEvent:] + 92
22 UIKit 0x0000000103c19e67 -[UIControl sendAction:to:forEvent:] + 67
23 UIKit 0x0000000103c1a143 -[UIControl _sendActionsForEvents:withEvent:] + 327
24 UIKit 0x0000000103c19263 -[UIControl touchesEnded:withEvent:] + 601
25 UIKit 0x0000000103b1999f -[UIWindow _sendTouchesForEvent:] + 835
26 UIKit 0x0000000103b1a6d4 -[UIWindow sendEvent:] + 865
27 UIKit 0x0000000103ac5dc6 -[UIApplication sendEvent:] + 263
28 UIKit 0x0000000103a9f553 _UIApplicationHandleEventQueue + 6660
29 CoreFoundation 0x0000000105095301 _CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION_ + 17
30 CoreFoundation 0x000000010508b22c __CFRunLoopDoSources0 + 556
31 CoreFoundation 0x000000010508a6e3 __CFRunLoopRun + 867
32 CoreFoundation 0x000000010508a0f8 CFRunLoopRunSpecific + 488
33 GraphicsServices 0x000000010726dad2 GSEventRunModal + 161
34 UIKit 0x0000000103aa4f09 UIApplicationMain + 171
35 Dhikr 0x0000000101f26282 main + 114
36 libdyld.dylib 0x00000001064c392d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
The code that I used is:
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
let foodList:[String] = ["Bread", "Meat", "Pizza", "Other"]
let drinkList:[String] = ["Water", "Soda", "Juice", "Other"]
#IBOutlet weak var mySegmentedControl: UISegmentedControl!
#IBOutlet weak var myTableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
var returnValue = 0
switch(mySegmentedControl.selectedSegmentIndex) {
case 0:
returnValue = foodList.count
break
case 1:
returnValue = drinkList.count
break
default:
break
}
return returnValue
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let myCell = tableView.dequeueReusableCellWithIdentifier("myCells", forIndexPath: indexPath)
switch(mySegmentedControl.selectedSegmentIndex) {
case 0:
myCell.textLabel!.text = foodList[indexPath.row]
break
case 1:
myCell.textLabel!.text = drinkList[indexPath.row]
break
default:
break
}
return myCell
}
#IBAction func segmentedControlActionChanged(sender: AnyObject) {
myTableView.reloadData()
}
Here is main.Storyboard
I checked the code many times, but it's not working. First I had to use only Table View, watching this tutorial (https://www.youtube.com/watch?v=ABVLSF3Vqdg) I thought it will work to use Segmented Control as in tutorial. But still doesn't work. Same code, same error.
Can someone help me ?
You have your storyboard set up to expect an outlet called tableView but the actual outlet name is myTableView.
If you delete the connection in the storyboard and reconnect to the right variable name, it should fix the problem.
Any chance that you changed the name of your table view from "tableView" to "myTableView" at some point?

Getting a Swift run-time error (NSException)

I'm relatively new to Swift programming and I'm getting a run-time that is irking me quite a bit and I'm not sure why this is occurring as the source code looks correct.
The run-time error leads me to this in the console:
'[<UIViewController 0x7ff27051a5f0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key btnRoll.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000103744e65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000105484deb objc_exception_throw + 48
2 CoreFoundation 0x0000000103744aa9 -[NSException raise] + 9
3 Foundation 0x0000000103b0d9bb -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288
4 UIKit 0x00000001040f0320 -[UIViewController setValue:forKey:] + 88
5 UIKit 0x000000010431ef41 -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x00000001036854a0 -[NSArray makeObjectsPerformSelector:] + 224
7 UIKit 0x000000010431d924 -[UINib instantiateWithOwner:options:] + 1864
8 UIKit 0x00000001040f6eea -[UIViewController _loadViewFromNibNamed:bundle:] + 381
9 UIKit 0x00000001040f7816 -[UIViewController loadView] + 178
10 UIKit 0x00000001040f7b74 -[UIViewController loadViewIfRequired] + 138
11 UIKit 0x00000001040f82e7 -[UIViewController view] + 27
12 UIKit 0x0000000103fceab0 -[UIWindow addRootViewControllerViewIfPossible] + 61
13 UIKit 0x0000000103fcf199 -[UIWindow _setHidden:forced:] + 282
14 UIKit 0x0000000103fe0c2e -[UIWindow makeKeyAndVisible] + 42
15 UIKit 0x0000000103f59663 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4131
16 UIKit 0x0000000103f5fcc6 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1760
17 UIKit 0x0000000103f5ce7b -[UIApplication workspaceDidEndTransaction:] + 188
18 FrontBoardServices 0x0000000107319754 -[FBSSerialQueue _performNext] + 192
19 FrontBoardServices 0x0000000107319ac2 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
20 CoreFoundation 0x0000000103670a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
21 CoreFoundation 0x000000010366695c __CFRunLoopDoSources0 + 556
22 CoreFoundation 0x0000000103665e13 __CFRunLoopRun + 867
23 CoreFoundation 0x0000000103665828 CFRunLoopRunSpecific + 488
24 UIKit 0x0000000103f5c7cd -[UIApplication _run] + 402
25 UIKit 0x0000000103f61610 UIApplicationMain + 171
26 Craps 0x00000001035652dd main + 109
27 libdyld.dylib 0x0000000105f8d92d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I only have 30 lines of code or so in the mini-game I created and I don't see why the error is coming up:
//
// ViewController.swift
// Craps
//
// Created by Lamido Tijjo on 2/11/16.
// Copyright © 2016 YauwaSarki. All rights reserved.
//
import UIKit
class CrapsViewController: UIViewController {
var rollDice1: Int = 0
var rollDice2: Int = 0
var rollTotal: Int = 0
#IBOutlet var lblRollOne: UILabel!
#IBOutlet var lblRollTwo: UILabel!
#IBOutlet var lblTotalRoll: UILabel!
#IBAction func btnRollDice(sender: AnyObject) {
rollDice1 = Int(arc4random() % 6) + 1
rollDice2 = Int(arc4random() % 6) + 1
rollTotal = rollDice1 + rollDice2
lblRollOne.text = String(rollDice1)
lblRollTwo.text = String(rollDice2)
if rollTotal != 7 || rollTotal != 11 {
lblTotalRoll.text = "Sorry you rolled a \(rollTotal), please try again!"
} else {
lblTotalRoll.text = "Congrats! you rolled a \(rollTotal), play again if you like!"
}
}
}
Can someone or some people please kindly shed some light on the situation. Thanks!
You have outlets defined for your view controller in a storyboard or .xib file. One of them is called "btnRoll" and was linked to the controller at some point. The matching property does not exist in code.
Possible reasons are: you deleted the code without unlinking the outlet or you have the wrong view controller defined as the view's owner.

popToViewController failed to pop to view error

I am using the following code:
#IBAction func popToRoot(sender:UIBarButtonItem){
navigationController.popToViewController(foodforteethViewController(), animated: false)
}
This function is linked with a custom back button and the h file is linked in the objective-c/swift bridging file. The issue with this is that I get an error as below:
2014-07-19 23:35:40.842 FoodForTeeth[9040:238499] * Assertion failure in -[UINavigationController popToViewController:transition:], /SourceCache/UIKit_Sim/UIKit-3232.3/UINavigationController.m:5345
2014-07-19 23:35:40.845 FoodForTeeth[9040:238499] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to get popped view controller.'
* First throw call stack:
(
0 CoreFoundation 0x00000001023ec995 exceptionPreprocess + 165
1 libobjc.A.dylib 0x000000010209b9a3 objc_exception_throw + 45
2 CoreFoundation 0x00000001023ec7fa +[NSException raise:format:arguments:] + 106
3 Foundation 0x0000000101cc637f -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
4 UIKit 0x0000000100b456b6 -[UINavigationController popToViewController:transition:] + 762
5 FoodForTeeth 0x00000001000272fe _TFC12FoodForTeeth9dietDiary9popToRootfS0_FCSo15UIBarButtonItemT_ + 302
6 FoodForTeeth 0x00000001000274f2 _TToFC12FoodForTeeth9dietDiary9popToRootfS0_FCSo15UIBarButtonItemT_ + 66
7 UIKit 0x00000001009f76b6 -[UIApplication sendAction:to:from:forEvent:] + 75
8 UIKit 0x00000001009f76b6 -[UIApplication sendAction:to:from:forEvent:] + 75
9 UIKit 0x0000000100af91c0 -[UIControl _sendActionsForEvents:withEvent:] + 467
10 UIKit 0x0000000100af858f -[UIControl touchesEnded:withEvent:] + 522
11 UIKit 0x0000000100a3c3b8 -[UIWindow _sendTouchesForEvent:] + 735
12 UIKit 0x0000000100a3cce3 -[UIWindow sendEvent:] + 683
13 UIKit 0x0000000100a0a1a1 -[UIApplication sendEvent:] + 246
14 UIKit 0x0000000100a1707a _UIApplicationHandleEventFromQueueEvent + 17591
15 UIKit 0x00000001009f3269 _UIApplicationHandleEventQueue + 1967
16 CoreFoundation 0x0000000102322a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17
17 CoreFoundation 0x000000010231826d __CFRunLoopDoSources0 + 269
18 CoreFoundation 0x00000001023178a4 __CFRunLoopRun + 868
19 CoreFoundation 0x00000001023172d6 CFRunLoopRunSpecific + 470
20 GraphicsServices 0x0000000105475bbc GSEventRunModal + 161
21 UIKit 0x00000001009f6288 UIApplicationMain + 1282
22 FoodForTeeth 0x0000000100054db3 main + 115
23 libdyld.dylib 0x0000000102b45145 start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
What's going wrong?
you can not pop a view controller which is not in NavigationController stack.You should pop like this
if you want pop to rootViewController than there is direct method use this
#IBAction func popToRoot(sender:UIBarButtonItem){
self.navigationController.popToRootViewControllerAnimated(false)
}
Another way to go back to a specific view controller would be to use unwind segues:
What are Unwind segues for and how do you use them?