2016-12-31 56 views
2

我有在buttonPressed IBAction爲不同的標籤10個連接UIButtons和我賽格瑞的ID爲「GoToDetailVC」應用程序崩潰時出現錯誤:「此類不是密鑰tableView的密鑰值編碼兼容」。怎麼修?

import UIKit 

class MainVC: UIViewController { 

var buttonNumber: Int? 

override func viewDidLoad() { 
    super.viewDidLoad() 
} 
override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
} 

@IBAction func buttonPressed(sender: AnyObject) { 
    buttonNumber = sender.tag 
    performSegue(withIdentifier: "GoToDetailVC", sender: sender.tag) 
} 

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    if let destination = segue.destination as? DetailVC { 
     if let btnNumber = sender as? Int { 
      destination.buttonNumber = btnNumber 
     } 
    } 
} 
} 

然後我想從標籤更換次數的headerLabel文本

import UIKit 

class DetailVC: UIViewController { 

@IBOutlet weak var headerLabel: UILabel! 

private var _buttonNumber: Int! 

var buttonNumber: Int { 
    get { 
     return _buttonNumber 
    } set { 
     _buttonNumber = newValue 
    } 
} 

override func viewDidLoad() { 
    super.viewDidLoad() 
    headerLabel.text = "\(_buttonNumber!)" 
} 
override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
} 

@IBAction func dismissView(_ sender: UIButton) { 
    dismiss(animated: true, completion: nil)   
} 
} 

它崩潰併產生這個消息

2016-12-31 12:36:36.439 Core Geometry[2638:539019] *** Terminating app  due to uncaught exception 'NSUnknownKeyException', reason:  '[<Core_Geometry.DetailVC 0x7fc55251aea0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key tableView.' 
*** First throw call stack: 
(
    0 CoreFoundation      0x0000000108a67d4b __exceptionPreprocess + 171 
1 libobjc.A.dylib      0x000000010615b21e objc_exception_throw + 48 
2 CoreFoundation      0x0000000108a67c99 -[NSException raise] + 9 
3 Foundation       0x0000000105c699df -[NSObject(NSKeyValueCoding) setValue:forKey:] + 291 
4 UIKit        0x00000001067be293 -[UIViewController setValue:forKey:] + 88 
5 UIKit        0x0000000106a3279e -[UIRuntimeOutletConnection connect] + 109 
6 CoreFoundation      0x0000000108a0c9e0 -[NSArray makeObjectsPerformSelector:] + 256 
7 UIKit        0x0000000106a31122 -[UINib instantiateWithOwner:options:] + 1867 
8 UIKit        0x00000001067c49c5 -[UIViewController _loadViewFromNibNamed:bundle:] + 386 
9 UIKit        0x00000001067c52e7 -[UIViewController loadView] + 177 
10 UIKit        0x00000001067c561c -[UIViewController loadViewIfRequired] + 201 
11 UIKit        0x00000001067c5e70 -[UIViewController view] + 27 
12 UIKit        0x00000001070866a4 -[_UIFullscreenPresentationController _setPresentedViewController:] + 87 
13 UIKit        0x00000001067a0702 -[UIPresentationController initWithPresentedViewController:presentingViewController:] + 141 
14 UIKit        0x00000001067d8e97 -[UIViewController _presentViewController:withAnimationController:completion:] + 3956 
15 UIKit        0x00000001067dc26b -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 530 
16 UIKit        0x00000001067dbd51 -[UIViewController presentViewController:animated:completion:] + 179 
17 UIKit        0x0000000106de9717 __74-[UIStoryboardPresentationSegueTemplate newDefaultPerformHandlerForSegue:]_block_invoke + 133 
18 UIKit        0x0000000106df91dd -[UIStoryboardSegueTemplate _performWithDestinationViewController:sender:] + 447 
19 UIKit        0x0000000106df8fed -[UIStoryboardSegueTemplate _perform:] + 82 
20 UIKit        0x00000001067c8a1f -[UIViewController performSegueWithIdentifier:sender:] + 99 
21 Core Geometry      0x00000001056c6de1 _TFC13Core_Geometry6MainVC13buttonPressedfT6senderPs9AnyObject__T_ + 465 
22 Core Geometry      0x00000001056c6f86 _TToFC13Core_Geometry6MainVC13buttonPressedfT6senderPs9AnyObject__T_ + 54 
23 UIKit        0x00000001066258bc -[UIApplication sendAction:to:from:forEvent:] + 83 
24 UIKit        0x00000001067abc38 -[UIControl sendAction:to:forEvent:] + 67 
25 UIKit        0x00000001067abf51 -[UIControl _sendActionsForEvents:withEvent:] + 444 
26 UIKit        0x00000001067aae4d -[UIControl touchesEnded:withEvent:] + 668 
27 UIKit        0x0000000106693545 -[UIWindow _sendTouchesForEvent:] + 2747 
28 UIKit        0x0000000106694c33 -[UIWindow sendEvent:] + 4011 
29 UIKit        0x00000001066419ab -[UIApplication sendEvent:] + 371 
30 UIKit        0x0000000106e2e72d __dispatchPreprocessedEventFromEventQueue + 3248 
31 UIKit        0x0000000106e27463 __handleEventQueue + 4879 
32 CoreFoundation      0x0000000108a0c761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17 
33 CoreFoundation      0x00000001089f198c __CFRunLoopDoSources0 + 556 
34 CoreFoundation      0x00000001089f0e76 __CFRunLoopRun + 918 
35 CoreFoundation      0x00000001089f0884 CFRunLoopRunSpecific + 420 
36 GraphicsServices     0x000000010a965a6f GSEventRunModal + 161 
37 UIKit        0x0000000106623c68 UIApplicationMain + 159 
38 Core Geometry      0x00000001056c654f main + 111 
39 libdyld.dylib      0x0000000105b8768d start + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
(lldb) 
+1

請發佈您在控制檯 –

+1

和郵編中獲得的完整錯誤,而不是代碼截圖 – luk2302

+0

滿意的傢伙? –

回答

1

顯然,什麼是錯在你的筆尖文件。嘗試先刪除tableView和其他視圖之間的所有連接。這意味着所有網點(IBOutlet)和行動(IBAction)。最有可能的是崩潰將消失。之後,您可以嘗試重新連接插座和操作,但請確保正確地執行操作。導致錯誤狀態表示您正在與tableView的類建立連接,但它沒有名爲tableView的密鑰(屬性)。所以你可能試圖與錯誤的類/對象建立聯繫。

+0

哎呀!完全正確!在泰國玩得開心! –

相關問題