How can I stop my swift app from crashing in simulator [duplicate] - iphone

This question already has answers here:
Xcode - How to fix 'NSUnknownKeyException', reason: … this class is not key value coding-compliant for the key X" error?
(79 answers)
Closed 6 years ago.
I am trying to build a tip calculator using swift 3 and Xcode. I have written a function and I am trying to simply test that and make sure it is doing what it should and I'll worry about formatting later. However, even without any build or run errors it crashes when I try to run it in the simulator. In regards to whatever answers I may receive, I am very new to this and my teacher doesn't have us using a book so I am not very familiar with the correct terminology. I have pasted my code and the crash log.
//
// ViewController.swift
// myTipCalculator
//
// Created by Mac User on 2/11/17.
// Copyright © 2017 Mac User. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
#IBOutlet weak var billAmount: UITextField!
#IBOutlet weak var fifteenTip: UIButton!
#IBOutlet weak var twentyTip: UIButton!
#IBOutlet weak var twentyFiveTip: UIButton!
#IBOutlet weak var tipTotal: UILabel!
#IBOutlet weak var grandTotal: UILabel!
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.
}
func calcTip(num1: Double, num2: Double){
print("Tip: \(num1 * num2)")
}
#IBAction func calcFifteen(_ sender: Any) {
let billA = Double(billAmount.text!)
let tipA = 0.15
calcTip(num1: billA!, num2: tipA)
}
#IBAction func calcTwenty(_ sender: Any) {
let billA = Double(billAmount.text!)
let tipA = 0.20
calcTip(num1: billA!, num2: tipA)
}
/*#IBAction func calcTwentyFive(_ sender: Any) {
let billA = Double(billAmount.text!)
let tipA = 0.25
calcTip(num1: billA!, num2: tipA)
}*/
}
2017-02-11 18:56:21.596 myTipCalculator[7087:101844] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<myTipCalculator.ViewController 0x7f89d3807b80> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key calcTwentyFive.'
*** First throw call stack:
(
0 CoreFoundation 0x0000000108692d4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010590b21e objc_exception_throw + 48
2 CoreFoundation 0x0000000108692c99 -[NSException raise] + 9
3 Foundation 0x00000001054199df -[NSObject(NSKeyValueCoding) setValue:forKey:] + 291
4 UIKit 0x0000000105f75293 -[UIViewController setValue:forKey:] + 88
5 UIKit 0x00000001061e979e -[UIRuntimeOutletConnection connect] + 109
6 CoreFoundation 0x00000001086379e0 -[NSArray makeObjectsPerformSelector:] + 256
7 UIKit 0x00000001061e8122 -[UINib instantiateWithOwner:options:] + 1867
8 UIKit 0x0000000105f7b9c5 -[UIViewController _loadViewFromNibNamed:bundle:] + 386
9 UIKit 0x0000000105f7c2e7 -[UIViewController loadView] + 177
10 UIKit 0x0000000105f7c61c -[UIViewController loadViewIfRequired] + 201
11 UIKit 0x0000000105f7ce70 -[UIViewController view] + 27
12 UIKit 0x0000000105e464b5 -[UIWindow addRootViewControllerViewIfPossible] + 71
13 UIKit 0x0000000105e46c06 -[UIWindow _setHidden:forced:] + 293
14 UIKit 0x0000000105e5a519 -[UIWindow makeKeyAndVisible] + 42
15 UIKit 0x0000000105dd2f8d -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4818
16 UIKit 0x0000000105dd90ed -[UIApplication _runWithMainScene:transitionContext:completion:] + 1731
17 UIKit 0x0000000105dd626d -[UIApplication workspaceDidEndTransaction:] + 188
18 FrontBoardServices 0x0000000109dce6cb __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
19 FrontBoardServices 0x0000000109dce544 -[FBSSerialQueue _performNext] + 189
20 FrontBoardServices 0x0000000109dce8cd -[FBSSerialQueue _performNextFromRunLoopSource] + 45
21 CoreFoundation 0x0000000108637761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
22 CoreFoundation 0x000000010861c98c __CFRunLoopDoSources0 + 556
23 CoreFoundation 0x000000010861be76 __CFRunLoopRun + 918
24 CoreFoundation 0x000000010861b884 CFRunLoopRunSpecific + 420
25 UIKit 0x0000000105dd4aea -[UIApplication _run] + 434
26 UIKit 0x0000000105ddac68 UIApplicationMain + 159
27 myTipCalculator 0x000000010532860f main + 111
28 libdyld.dylib 0x000000010963c68d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

Try to remove the comments from this action: calcTwentyFive, and run your App. If that didn't help you, check out all of your outlets and actions.
It seems that you forgot to list one of your actions/outlet in UIViewController. Basically, click on each item you have in Main.StoryBoard, and click the arrow to the right to check the connection as the following image:
Make sure all of your outlets and actions are found in UIViewController.

Related

Function to decrement label does not work [duplicate]

I am making an app that requires a user to press one of two UIButtons and then prints a response depending on which button was pressed (determined based on the tag of the button pressed). However, when I run press button, I get an
Unrecognized selector sent to instance
How do I resolve this?
Here's my code. The IBAction at the bottom refers to the UIButtons that are causing the error:
import UIKit
class ViewController: UIViewController {
let story1 = "This is the story."
let answer1 = "No change"
let answer2 = "Lose 1 health"
var healthStat : Int = 10
#IBOutlet weak var storyText: UILabel!
#IBOutlet weak var health: UILabel!
#IBOutlet weak var restartButton: UILabel!
#IBOutlet weak var choiceOne: UIButton!
#IBOutlet weak var choiceTwo: UIButton!
var storyIndex = 1
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
storyText.text = story1
choiceOne.setTitle("\(answer1)", for: .normal)
choiceTwo.setTitle("\(answer2)", for: .normal)
health.text = String("Health: \(healthStat)")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
#IBAction func buttonPressed(_ sender: UIButton) {
if sender.tag == 1 {
print("Option 1 selected")
}
else if sender.tag == 2 {
print("Option 2 selected. Lose 1 health.")
healthStat = healthStat - 1
}
}
}
Here is the entirety of the error:
2017-07-29 21:45:24.626 Choose Your Own Adventure[16001:694686] -[Choose_Your_Own_Adventure.ViewController buttonOnePressed:]: unrecognized selector sent to instance 0x7fc199c0cfe0
2017-07-29 21:45:24.638 Choose Your Own Adventure[16001:694686] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Choose_Your_Own_Adventure.ViewController buttonOnePressed:]: unrecognized selector sent to instance 0x7fc199c0cfe0'
*** First throw call stack:
(
0 CoreFoundation 0x0000000113504b0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000011037e141 objc_exception_throw + 48
2 CoreFoundation 0x0000000113574134 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x000000011348b840 ___forwarding___ + 1024
4 CoreFoundation 0x000000011348b3b8 _CF_forwarding_prep_0 + 120
5 UIKit 0x0000000110c66d82 -[UIApplication sendAction:to:from:forEvent:] + 83
6 UIKit 0x0000000110deb5ac -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x0000000110deb8c7 -[UIControl _sendActionsForEvents:withEvent:] + 450
8 UIKit 0x0000000110dea802 -[UIControl touchesEnded:withEvent:] + 618
9 UIKit 0x0000000110cd47ea -[UIWindow _sendTouchesForEvent:] + 2707
10 UIKit 0x0000000110cd5f00 -[UIWindow sendEvent:] + 4114
11 UIKit 0x0000000110c82a84 -[UIApplication sendEvent:] + 352
12 UIKit 0x00000001114665d4 __dispatchPreprocessedEventFromEventQueue + 2926
13 UIKit 0x000000011145e532 __handleEventQueue + 1122
14 CoreFoundation 0x00000001134aac01 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
15 CoreFoundation 0x00000001134900cf __CFRunLoopDoSources0 + 527
16 CoreFoundation 0x000000011348f5ff __CFRunLoopRun + 911
17 CoreFoundation 0x000000011348f016 CFRunLoopRunSpecific + 406
18 GraphicsServices 0x000000011542da24 GSEventRunModal + 62
19 UIKit 0x0000000110c65134 UIApplicationMain + 159
20 Choose Your Own Adventure 0x000000010fd9efa7 main + 55
21 libdyld.dylib 0x00000001144a465d start + 1
22 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
It seems like you have rename your IBAction method name earlier it was different and it is connected to the previous name inside your storyboard. So just disconnect your action method and reconnect it appropriately.

Thread 1: signal SIGABRT error due to Button

I am still learning swift and Xcode so please explain as much as possible in layman's terms so i can understand and try to fix this issue, i'm getting a sigbrt error, but not sure why. Ive created tons of buttons and linked it to the viewcontroller.swift which i have done, but for the life of me, i can not see why i am getting this error. Any help would be very much appreciated.
First here is the debug error:
2018-11-26 20:30:42.713790+0000 Numbers[2058:130834] -[Numerology.twoViewController generateYourNumbersButtonPress:]: unrecognized selector sent to instance 0x7fac2973d5a0
2018-11-26 20:30:42.724547+0000 Numbers[2058:130834] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Numbers.twoViewController generateYourNumbersButtonPress:]: unrecognized selector sent to instance 0x7fac2973d5a0'
*** First throw call stack:
(
0 CoreFoundation 0x0000000107e6a1bb __exceptionPreprocess + 331
1 libobjc.A.dylib 0x0000000106448735 objc_exception_throw + 48
2 CoreFoundation 0x0000000107e88f44 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 UIKitCore 0x000000010a823b4a -[UIResponder doesNotRecognizeSelector:] + 287
4 CoreFoundation 0x0000000107e6eed6 ___forwarding___ + 1446
5 CoreFoundation 0x0000000107e70da8 _CF_forwarding_prep_0 + 120
6 UIKitCore 0x000000010a7f6ecb -[UIApplication sendAction:to:from:forEvent:] + 83
7 UIKitCore 0x000000010a2320bd -[UIControl sendAction:to:forEvent:] + 67
8 UIKitCore 0x000000010a2323da -[UIControl _sendActionsForEvents:withEvent:] + 450
9 UIKitCore 0x000000010a23131e -[UIControl touchesEnded:withEvent:] + 583
10 UIKitCore 0x000000010a8320a4 -[UIWindow _sendTouchesForEvent:] + 2729
11 UIKitCore 0x000000010a8337a0 -[UIWindow sendEvent:] + 4080
12 UIKitCore 0x000000010a811394 -[UIApplication sendEvent:] + 352
13 UIKitCore 0x000000010a8e65a9 __dispatchPreprocessedEventFromEventQueue + 3054
14 UIKitCore 0x000000010a8e91cb __handleEventQueueInternal + 5948
15 CoreFoundation 0x0000000107dcf721 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
16 CoreFoundation 0x0000000107dcef93 __CFRunLoopDoSources0 + 243
17 CoreFoundation 0x0000000107dc963f __CFRunLoopRun + 1263
18 CoreFoundation 0x0000000107dc8e11 CFRunLoopRunSpecific + 625
19 GraphicsServices 0x000000010ff861dd GSEventRunModal + 62
20 UIKitCore 0x000000010a7f581d UIApplicationMain + 140
21 Numbers 0x0000000105b17ed7 main + 71
22 libdyld.dylib 0x0000000109303575 start + 1
23 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
Below is My Code:
import UIKit
class twoViewController: UIViewController {
let ballArray = ["brownBall1","brownBall2","bbrownBall3","brownBall4","brownball5","lightBlue6","lightBlue7","lightBlue8","lightBlue9","lightBlue10","yellowBall11","yellowBall12","yellowBall13","yellowBall14","yellowball15","silverBall16","silverBall17","silverBall18","silverBall19","silverBall20","redBall21","redBall22","redBall23","redBall24","redBall25","purpleBall26","purpleBall27","purpleBall28","purpleBall29","purpleBall30","greenBall31","greenball32","greenball33","greenball34","greenBall35","goldBall36","goldBall37","goldBall38","goldBall39","goldBall40","blueBall41","blueBall42","blueBall43","blueBall44","blueball45","blackBall46","blackBall47","blackBall48","blackBall49","blackBall50"]
let luckyStarArray = ["goldOne", "goldTwo", "goldThree", "goldFour", "goldFive", "goldSix", "goldSeven", "goldEight", "goldBballNine"]
#IBOutlet weak var starView1: UIImageView!
#IBOutlet weak var starView2: UIImageView!
#IBOutlet weak var starView3: UIImageView!
#IBOutlet weak var starView4: UIImageView!
#IBOutlet weak var starView5: UIImageView!
#IBOutlet weak var luckyStar1: UIImageView!
#IBOutlet weak var luckyStar2: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
func generateYourNumbersButtonPress(_ sender: UIButton) {
let shuffledBallArray = ballArray.shuffled()
starView1.image = UIImage(named: shuffledBallArray[0])
starView2.image = UIImage(named: shuffledBallArray[1])
starView3.image = UIImage(named: shuffledBallArray[2])
starView4.image = UIImage(named: shuffledBallArray[3])
starView5.image = UIImage(named: shuffledBallArray[4])
let shuffledLuckyBallArray = luckyStarArray.shuffled()
luckyStar1.image = UIImage(named: shuffledLuckyBallArray[0])
luckyStar2.image = UIImage(named: shuffledLuckyBallArray[1])
}
}
}
First, don't put generateYourNumbersButtonPress inside of viewDidLoad.
Second, mark generateYourNumbersButtonPress as an #IBAction.
Third, reconnect the action to the button after fixing the above two issues so you connect the proper action method to the button's event.

Swift 3 - Thread 1: Signal SIGABRT Unrecognised selector sent to Instance

could any please help me solve this problem? I have been at it trying to fix the issue for a few hours but nothing has worked so far. Everytime I click a button it immediately leads to the error Thread 1: Signal SIGABRT.
This is the code (Note: It is still a work in Progress):
import UIKit
class ViewController: UIViewController {
#IBOutlet var Sec1: UILabel!
#IBOutlet var Sec2: UILabel!
#IBOutlet var Sec3: UILabel!
#IBOutlet var Sec4: UILabel!
#IBOutlet var Sec5: UILabel!
#IBOutlet var Sec6: UILabel!
#IBOutlet var Sec7: UILabel!
#IBOutlet var Sec8: UILabel!
#IBOutlet var Sec9: UILabel!
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.
}
var x = 2
// if (x%2 == 0) {
#IBAction func ButtonPressed(Button1: UIButton) {
Sec1.text = "X"
}
}
This is the Error:
**2017-02-23 07:58:14.194 Tic Tac Toe IS[46707:2457511] -[Tic_Tac_Toe_IS.ViewController ButtonPressed:]: unrecognized selector sent to instance 0x7fb8a8d04ee0
2017-02-23 07:58:14.202 Tic Tac Toe IS[46707:2457511] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Tic_Tac_Toe_IS.ViewController ButtonPressed:]: unrecognized selector sent to instance 0x7fb8a8d04ee0'
*** First throw call stack:
(
0 CoreFoundation 0x000000010bebfd4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00000001092be21e objc_exception_throw + 48
2 CoreFoundation 0x000000010bf2ff04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x000000010be45005 ___forwarding___ + 1013
4 CoreFoundation 0x000000010be44b88 _CF_forwarding_prep_0 + 120
5 UIKit 0x000000010978f8bc -[UIApplication sendAction:to:from:forEvent:] + 83
6 UIKit 0x0000000109915c38 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x0000000109915f51 -[UIControl _sendActionsForEvents:withEvent:] + 444
8 UIKit 0x0000000109914e4d -[UIControl touchesEnded:withEvent:] + 668
9 UIKit 0x00000001097fd545 -[UIWindow _sendTouchesForEvent:] + 2747
10 UIKit 0x00000001097fec33 -[UIWindow sendEvent:] + 4011
11 UIKit 0x00000001097ab9ab -[UIApplication sendEvent:] + 371
12 UIKit 0x0000000109f9872d __dispatchPreprocessedEventFromEventQueue + 3248
13 UIKit 0x0000000109f91463 __handleEventQueue + 4879
14 CoreFoundation 0x000000010be64761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
15 CoreFoundation 0x000000010be4998c __CFRunLoopDoSources0 + 556
16 CoreFoundation 0x000000010be48e76 __CFRunLoopRun + 918
17 CoreFoundation 0x000000010be48884 CFRunLoopRunSpecific + 420
18 GraphicsServices 0x000000010ddf9a6f GSEventRunModal + 161
19 UIKit 0x000000010978dc68 UIApplicationMain + 159
20 Tic Tac Toe IS 0x0000000108cdb7af main + 111
21 libdyld.dylib 0x000000010ce6f68d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)**
Could you check the connection between your #IBAction func ButtonPressed() with storyboard? You can check it from the "Connection inspector" on the storyboard.

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.

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?