2016-01-17 66 views
0

我有一些UIButtons當我加載視圖控制器應用crashs,當我刪除UIbuttons應用工程和負載的UIButton曹景偉崩潰

這是發生了什麼

2016-01-17 16:27:51.151 HHKNBK[36147:32655609] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<HHKNBK.ViewController 0x7fed73052380> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key one.' 

*** First throw call stack: 
(
    0 CoreFoundation      0x000000010f757e65 __exceptionPreprocess + 165 
    1 libobjc.A.dylib      0x00000001116bfdeb objc_exception_throw + 48 
    2 CoreFoundation      0x000000010f757aa9 -[NSException raise] + 9 
    3 Foundation       0x000000010fd489bb -[NSObject(NSKeyValueCoding) setValue:forKey:] + 288 
    4 UIKit        0x000000011032b320 -[UIViewController setValue:forKey:] + 88 
    5 UIKit        0x0000000110559f41 -[UIRuntimeOutletConnection connect] + 109 
    6 CoreFoundation      0x000000010f6984a0 -[NSArray makeObjectsPerformSelector:] + 224 
    7 UIKit        0x0000000110558924 -[UINib instantiateWithOwner:options:] + 1864 
    8 UIKit        0x0000000110331eea -[UIViewController _loadViewFromNibNamed:bundle:] + 381 
    9 UIKit        0x0000000110332816 -[UIViewController loadView] + 178 
    10 UIKit        0x0000000110332b74 -[UIViewController loadViewIfRequired] + 138 
    11 UIKit        0x00000001103332e7 -[UIViewController view] + 27 
    12 UIKit        0x00000001103858b0 -[UINavigationController preferredContentSize] + 194 
    13 UIKit        0x000000011030a0aa -[UIPresentationController preferredContentSizeDidChangeForChildContentContainer:] + 59 
    14 UIKit        0x0000000110306438 __56-[UIPresentationController runTransitionForCurrentState]_block_invoke + 95 
    15 UIKit        0x00000001101a84a2 _runAfterCACommitDeferredBlocks + 317 
    16 UIKit        0x00000001101bbc01 _cleanUpAfterCAFlushAndRunDeferredBlocks + 95 
    17 UIKit        0x00000001101c7af3 _afterCACommitHandler + 90 
    18 CoreFoundation      0x000000010f683367 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 23 
    19 CoreFoundation      0x000000010f6832d7 __CFRunLoopDoObservers + 391 
    20 CoreFoundation      0x000000010f678f2b __CFRunLoopRun + 1147 
    21 CoreFoundation      0x000000010f678828 CFRunLoopRunSpecific + 488 
    22 GraphicsServices     0x000000011486cad2 GSEventRunModal + 161 
    23 UIKit        0x000000011019c610 UIApplicationMain + 171 
    24 HHKNBK        0x000000010f10677d main + 109 
    25 libdyld.dylib      0x00000001121d192d start + 1 
    26 ???         0x0000000000000001 0x0 + 1 
) 
libc++abi.dylib: terminating with uncaught exception of type NSException 
(lldb) 

下面是代碼

import UIKit 

class ViewController: UIViewController { 


    @IBOutlet var live: mainbutton! 

    @IBOutlet var dt: mainbutton! 

    @IBOutlet var ms: mainbutton! 
    @IBOutlet var `as1`: mainbutton! 
    @IBOutlet var read: mainbutton! 
    @IBOutlet var pg: mainbutton! 


    override func viewDidLoad() { 
     super.viewDidLoad() 


     self.view.backgroundColor = color125 

     live.setTitle("Live", forState: UIControlState.Normal) 
     dt.setTitle("Dhamma Talk", forState: UIControlState.Normal) 
     ms.setTitle("Mediations Stream", forState: UIControlState.Normal) 
     as1.setTitle("Adavanced And Special Streams", forState: UIControlState.Normal) 
     read.setTitle("Read", forState: UIControlState.Normal) 
     pg.setTitle("Program Guide", forState: UIControlState.Normal) 


     // 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. 
    } 


} 

應用代表

import UIKit 

@UIApplicationMain 
class AppDelegate: UIResponder, UIApplicationDelegate { 

    var window: UIWindow? 

    func grabStoryboard() -> UIStoryboard { 
     var storyboard = UIStoryboard() 
     let height = UIScreen.mainScreen().bounds.size.height 

     if height == 480 { 
      storyboard = UIStoryboard(name: "main3.5", bundle: nil) 
     } else if height == 568 { 
      storyboard = UIStoryboard(name: "main4", bundle: nil) 
     } else if height == 667 { 
      storyboard = UIStoryboard(name: "main6", bundle: nil) 
     } else if height == 736 { 
      storyboard = UIStoryboard(name: "main6plus", bundle: nil) 
     } else { 
      storyboard = UIStoryboard(name: "Main", bundle: nil) 
     } 

     return storyboard 
    } 

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 
     // Override point for customization after application launch. 


    UINavigationBar.appearance().barTintColor = color125 


     let storyboard: UIStoryboard = self.grabStoryboard() 

     self.window?.rootViewController = 
      storyboard.instantiateInitialViewController()! as UIViewController 
     self.window?.makeKeyAndVisible() 
     return true 
    } 

海關類代碼

override func awakeFromNib() { 
     self.backgroundColor = color125 
     self.layer.cornerRadius = 5 
     self.setTitleColor(UIColor.blackColor(), forState: .Normal) 
} 

回答

0

我覺得這行是罪魁禍首 -

@IBOutlet var `as1`: mainbutton! 

刪除這些報價

@IBOutlet var as1: mainbutton! 
1

該錯誤消息表示,他們是一個缺失的環節以獲得出口其名稱是「one」(「關鍵之一」)。

2016年1月17日16:27:51.151 HHKNBK [36147:32655609] ***終止應用程序由於 未捕獲的異常 'NSUnknownKeyException',原因: 「[setValue方法:forUndefinedKey:]: 這個類不是關鍵的編碼密鑰值。「

發生了什麼事情是「one」最初創建(ctrl鍵拖放)的出口,但變量名已在代碼中更改。

作爲一個例子,我已經創建了一個出口名稱爲 「一個」 以及:

@IBOutlet weak var one: UIButton! // Initially working 

然後改名爲一個改變

@IBOutlet weak var changed: UIButton! // <- Now broken outlet 

現在我得到的同樣的錯誤信息:

2016-01-17 18:56:14.059 InvalidOutlet [10158:5713712] ***終止 應用程序由於未捕獲異常'NSUnknownKeyException',原因: '[ setValue:forUndefinedKey:]:此類不是鍵值 編碼符合關鍵之一'。

要解決該問題,請通過

  1. 打開定義出口故事板擺脫無效的出口參考。
  2. 選擇定義出口的組件。
  3. 打開「顯示連接督察」(圓圈與箭頭右上方)
  4. 刪除無效的口,因爲展現在屏幕捕獲

Connections inspector