Hi I am getting following error while running table view controller.
I am trying to diplay some harcoded text in UITableViewController.
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSSingleObjectArrayI objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
*** First throw call stack:
(
0 CoreFoundation 0x000000010e79134b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010baab21e objc_exception_throw + 48
2 CoreFoundation 0x000000010e7e9bdf -[__NSSingleObjectArrayI objectAtIndex:] + 111
3 UIKit 0x000000010c738fe9 -[UITableViewDataSource tableView:heightForRowAtIndexPath:] + 181
4 UIKit 0x000000010c39c06b -[UITableViewController tableView:heightForRowAtIndexPath:] + 63
5 UIKit 0x000000010c0f1d7e -[UITableView _dataSourceHeightForRowAtIndexPath:] + 99
6 UIKit 0x000000010c32bac6 __66-[UISectionRowData refreshWithSection:tableView:tableViewRowData:]_block_invoke + 368
7 UIKit 0x000000010c32b081 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 3375
8 UIKit 0x000000010c330d31 -[UITableViewRowData rectForFooterInSection:heightCanBeGuessed:] + 501
9 UIKit 0x000000010c330e8f -[UITableViewRowData heightForTable] + 56
10 UIKit 0x000000010c0b2f36 -[UITableView _updateContentSize] + 381
11 UIKit 0x000000010c0db46f -[UITableView _rebuildGeometry] + 40
12 UIKit 0x000000010c0d96e3 -[UITableView setLayoutMargins:] + 282
13 UIKit 0x000000010c0d95a7 -[UITableView _setDefaultLayoutMargins:] + 103
14 UIKit 0x000000010c1127dc -[UIViewController _setContentOverlayInsets:] + 646
15 UIKit 0x000000010c112de2 -[UIViewController _updateContentOverlayInsetsFromParentIfNecessary] + 1000
16 UIKit 0x000000010c112859 -[UIViewController _updateContentOverlayInsetsForSelfAndChildren] + 101
17 UIKit 0x000000010c11e2d8 -[UIViewController _updateLayoutForStatusBarAndInterfaceOrientation] + 1027
18 UIKit 0x000000010c124002 -[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:] + 1238
19 UIKit 0x000000010c038620 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1590
20 UIKit 0x000000010c0500e2 -[UIScrollView _didMoveFromWindow:toWindow:] + 85
21 UIKit 0x000000010c02b6b4 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 151
22 UIKit 0x000000010c02b5a2 -[UIView(Hierarchy) _postMovedFromSuperview:] + 857
23 UIKit 0x000000010c03b2eb -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1982
24 UIKit 0x000000010c0297a1 -[UIView(Hierarchy) addSubview:] + 838
25 UIKit 0x000000010bfe5f5b -[UIWindow addRootViewControllerViewIfPossible] + 849
26 UIKit 0x000000010bfe63a2 -[UIWindow _setHidden:forced:] + 293
27 UIKit 0x000000010bff9cb5 -[UIWindow makeKeyAndVisible] + 42
28 UIKit 0x000000010bf72c89 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 4818
29 UIKit 0x000000010bf78de9 -[UIApplication _runWithMainScene:transitionContext:completion:] + 1731
30 UIKit 0x000000010bf75f69 -[UIApplication workspaceDidEndTransaction:] + 188
31 FrontBoardServices 0x000000011468a723 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK__ + 24
32 FrontBoardServices 0x000000011468a59c -[FBSSerialQueue _performNext] + 189
33 FrontBoardServices 0x000000011468a925 -[FBSSerialQueue _performNextFromRunLoopSource] + 45
34 CoreFoundation 0x000000010e736311 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
35 CoreFoundation 0x000000010e71b59c __CFRunLoopDoSources0 + 556
36 CoreFoundation 0x000000010e71aa86 __CFRunLoopRun + 918
37 CoreFoundation 0x000000010e71a494 CFRunLoopRunSpecific + 420
38 UIKit 0x000000010bf747e6 -[UIApplication _run] + 434
39 UIKit 0x000000010bf7a964 UIApplicationMain + 159
40 swift_mvp 0x000000010b2dec2f main + 111
41 libdyld.dylib 0x000000010f6c468d start + 1
42 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
I am trying to run simple TableView controller
Code for table view controller is as follows:
import Foundation
import UIKit
class FeedsTableViewController: UITableViewController, UserView {
private var userPresenter: UserPresenter?
override func viewDidLoad() {
super.viewDidLoad()
userPresenter = UserPresenter(userView: self)
//userPresenter?.getUsers()
}
func startLoading() {
print("Loading started")
}
func stopLoading() {
print("Stop loading")
}
func onEmpty() {
print("No users available")
}
func onUsers(users: [User]) {
print("Users \(users.count)")
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
print("number of section row fine")
return 10
}
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
print("number Getting item")
let cellItem = tableView.dequeueReusableCell(withIdentifier: "USER_ITEM_ROW", for: indexPath)
//cellItem.textLabel?.text = "sdadas"
return cellItem
}
}
Related
I have a Core Data problem - I have two entity's with the second being a one to many relation ship to the first. When trying to load a detailed view controller on the first with the first one's information and a UITableView fo the details of the 2nd, I am hoping this tableView code would allow me to show a blank table if now records are found. Instead I get a crash as indicated above. I have tried to cover the "Event" (the related NSSet) into an array, but I am not sure how to debug this error. Thanks for any pointers!
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "eventCell", for: indexPath)
let eventsOnArray = selectedRecipient?.events.allObjects
let event = eventsOnArray![indexPath.row] as! Event
if selectedRecipient?.events.count != nil {
cell.textLabel?.text = event.event
}
return cell
}
Adding detailed Stack Trace -
2018-03-03 10:27:29.419115-0500 Card Tracker[5162:453078] -[Recipient events]: unrecognized selector sent to instance 0x60000009cbb0
2018-03-03 10:27:29.427781-0500 Card Tracker[5162:453078] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Recipient events]: unrecognized selector sent to instance 0x60000009cbb0'
*** First throw call stack:
(
0 CoreFoundation 0x0000000107fd212b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000103d79f41 objc_exception_throw + 48
2 CoreFoundation 0x0000000108053024 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x0000000107f54f78 ___forwarding___ + 1432
4 CoreFoundation 0x0000000107f54958 _CF_forwarding_prep_0 + 120
5 Card Tracker 0x0000000103434fca _T012Card_Tracker010ViewEventsC10ControllerC05tableC0SiSo07UITableC0C_Si21numberOfRowsInSectiontF + 410
6 Card Tracker 0x00000001034352e4 _T012Card_Tracker010ViewEventsC10ControllerC05tableC0SiSo07UITableC0C_Si21numberOfRowsInSectiontFTo + 68
7 UIKit 0x0000000104cd1b4c -[UITableView _numberOfRowsInSection:] + 62
8 UIKit 0x0000000104f840e1 -[UISectionRowData refreshWithSection:tableView:tableViewRowData:] + 2389
9 UIKit 0x0000000104f8a5ab -[UITableViewRowData rectForFooterInSection:heightCanBeGuessed:] + 487
10 UIKit 0x0000000104f8a711 -[UITableViewRowData heightForTable] + 61
11 UIKit 0x0000000104c7fa65 -[UITableView _updateContentSize] + 372
12 UIKit 0x0000000104cb067d -[UITableView _rebuildGeometry] + 66
13 UIKit 0x0000000104cae03c -[UITableView didMoveToWindow] + 145
14 UIKit 0x0000000104c2b147 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1748
15 UIKit 0x0000000104c44a81 -[UIScrollView _didMoveFromWindow:toWindow:] + 84
16 UIKit 0x0000000104c2ad84 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 785
17 UIKit 0x0000000104c1d1e1 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 151
18 UIKit 0x0000000104c1d0c8 -[UIView(Hierarchy) _postMovedFromSuperview:] + 828
19 UIKit 0x0000000104c2dcbd -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1973
20 UIKit 0x0000000104b504e7 -[_UIParallaxDimmingView didMoveToWindow] + 179
21 UIKit 0x0000000104c2b147 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1748
22 UIKit 0x0000000104c2ad84 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 785
23 UIKit 0x0000000104c1d1e1 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 151
24 UIKit 0x0000000104c1d0c8 -[UIView(Hierarchy) _postMovedFromSuperview:] + 828
25 UIKit 0x0000000104c2dcbd -[UIView(Internal) _addSubview:positioned:relativeTo:] + 1973
26 UIKit 0x0000000104b4b259 __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke_2 + 2305
27 UIKit 0x0000000104c25c60 +[UIView(Animation) performWithoutAnimation:] + 90
28 UIKit 0x0000000104b4a903 __53-[_UINavigationParallaxTransition animateTransition:]_block_invoke + 260
29 UIKit 0x0000000104c2c271 +[UIView(Internal) _performBlockDelayingTriggeringResponderEvents:] + 188
30 UIKit 0x0000000104b4a21b -[_UINavigationParallaxTransition animateTransition:] + 1270
31 UIKit 0x0000000104d3e3ee -[UINavigationController _startCustomTransition:] + 3678
32 UIKit 0x0000000104d543b4 -[UINavigationController _startDeferredTransitionIfNeeded:] + 686
33 UIKit 0x0000000104d556d3 -[UINavigationController __viewWillLayoutSubviews] + 150
34 UIKit 0x0000000104fb04e2 -[UILayoutContainerView layoutSubviews] + 231
35 UIKit 0x0000000121187008 -[UILayoutContainerViewAccessibility layoutSubviews] + 42
36 UIKit 0x0000000104c34a6d -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1439
37 QuartzCore 0x000000010b5d361c -[CALayer layoutSublayers] + 159
38 QuartzCore 0x000000010b5d77ad _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 401
39 QuartzCore 0x000000010b55e86c _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 364
40 QuartzCore 0x000000010b58b946 _ZN2CA11Transaction6commitEv + 500
41 UIKit 0x0000000104b8d167 _afterCACommitHandler + 272
42 CoreFoundation 0x0000000107f74c07 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23
43 CoreFoundation 0x0000000107f74b5e __CFRunLoopDoObservers + 430
44 CoreFoundation 0x0000000107f59124 __CFRunLoopRun + 1572
45 CoreFoundation 0x0000000107f58889 CFRunLoopRunSpecific + 409
46 GraphicsServices 0x000000010a77b9c6 GSEventRunModal + 62
47 UIKit 0x0000000104b635d6 UIApplicationMain + 159
48 Card Tracker 0x0000000103417ea7 main + 55
49 libdyld.dylib 0x0000000109170d81 start + 1
50 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Two problems uncovered. one in the data model the secondary entity is called card not events. And two as pointed out by #vadian above should do the load in the viewDidLoad. Thanks
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.
I'm trying to set size for my cell according to what's inside
this is my code and it crashes and I can't find an error messege.
extension TimelineCollectionVC: UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "timeline", for: indexPath) as? Timeline
cell?.textView.translatesAutoresizingMaskIntoConstraints = true
cell?.textView.sizeToFit()
if cell?.containerView.subviews.count == 0 {
cell?.containerHeight.constant = 1
} else {
cell?.containerHeight.constant = (cell?.containerView.subviews.first?.frame.size.height) ?? 80
}
let cellHeight = (cell?.upperView.bounds.height)! + (cell?.textView.bounds.height)! + (cell?.containerView.bounds.height)! + (cell?.lowerView.bounds.height)!
return CGSize(width: 375, height: cellHeight)
}
}
reason: '-[NSCFString setSizeHasBeenSet:]: unrecognized selector sent to instance 0x610000076bc0'
*** First throw call stack:
(
0 CoreFoundation 0x0000000109dd9d4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00000001094d921e objc_exception_throw + 48
2 CoreFoundation 0x0000000109e49f04 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x0000000109d5f005 ___forwarding_ + 1013
4 CoreFoundation 0x0000000109d5eb88 _CF_forwarding_prep_0 + 120
5 UIKit 0x00000001080d9485 -[UICollectionViewFlowLayout _getSizingInfosWithExistingSizingDictionary:] + 3691
6 UIKit 0x00000001080da97b -[UICollectionViewFlowLayout _fetchItemsInfoForRect:] + 127
7 UIKit 0x00000001080d3504 -[UICollectionViewFlowLayout prepareLayout] + 273
8 UIKit 0x00000001080f3d6c -[UICollectionViewData _prepareToLoadData] + 159
9 UIKit 0x00000001080f4618 -[UICollectionViewData validateLayoutInRect:] + 57
10 UIKit 0x000000010809b6d4 -[UICollectionView layoutSubviews] + 232
11 UIKit 0x0000000107817ab8 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 1237
12 QuartzCore 0x0000000106fcdbf8 -[CALayer layoutSublayers] + 146
13 QuartzCore 0x0000000106fc1440 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366
14 QuartzCore 0x0000000106fc12be _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24
15 QuartzCore 0x0000000106f4f318 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 280
16 QuartzCore 0x0000000106f7c3ff _ZN2CA11Transaction6commitEv + 475
17 QuartzCore 0x0000000106f7cd6f _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 113
18 CoreFoundation 0x0000000109d7e267 CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION + 23
19 CoreFoundation 0x0000000109d7e1d7 __CFRunLoopDoObservers + 391
20 CoreFoundation 0x0000000109d628a6 CFRunLoopRunSpecific + 454
21 UIKit 0x000000010774caea -[UIApplication _run] + 434
22 UIKit 0x0000000107752c68 UIApplicationMain + 159
23 Moden 0x0000000104ab4fbf main + 111
24 libdyld.dylib 0x000000010ad4e68d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
You should not be using dequeueReusableCell here. That is only for creating new cells. In this case you want to get an existing cell and should probably be using func cellForItem(at indexPath: IndexPath) -> UICollectionViewCell? in the UICollectionView class.
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.
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?