2017-05-28 144 views
-2

我最近開始學習Swift,需要幫助。該程序運行良好之前,但我不知道我做了什麼,現在它不工作,按鈕不會出現,並在一個屏幕上崩潰。一個錯誤說:「由於未捕獲的異常'NSUnknownKeyExeption',原因:[setValue:forUndefinedKey:]終止應用程序:此類不是密鑰nextButton編碼兼容的關鍵值。 Ive得到你點擊進入到下一個屏幕按鈕,但我點擊它,它崩潰繼承人的代碼上HomeViewController,SecondScreenViewController和ThirdScreenViewController在Swift中更改屏幕視圖3

HomeViewController

@IBAction func notifiyButtonPressed(_ sender: AnyObject) { 

    print("Pressed") 
    self.performSegue(withIdentifier: "ViewSegue", sender: self) 
} 
override func viewDidLoad() { 
    super.viewDidLoad() 
    // Do any additional setup after loading the view, typically from a nib. 

    print("View has loaded! ") 

} 

override func didReceiveMemoryWarning() { 
    super.didReceiveMemoryWarning() 
    // Dispose of any resources that can be recreated. 
} 

SecondScreenViewController:。

@IBOutlet var textField: UITextField! 


@IBAction func nextButtonPressed(_ sender: Any) { 

    self.performSegue(withIdentifier: "whotoclass", sender: self) 
} 

override func viewDidLoad() { 
    super.viewDidLoad() 

    self.textField.delegate = self 
    print("View 2 Loaded") 

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


//Hide Keyboard when user touches outside keybaord 
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) { 
    self.view.endEditing(true) 
} 

//Presses return key 
func textFieldShouldReturn(_ textField: UITextField) -> Bool { 
    textField.resignFirstResponder() 
    return(true) 
} 

ThirdScreenViewController:

import UIKit 

類ThirdScreenViewController:UIViewController的{

@IBOutlet var joshClassButton: UIButton! 
@IBAction func joshClassButton(_ sender: Any) { 

    self.performSegue(withIdentifier: "classtoperiod", sender: self) 

} 

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

此外,隸屬是我Main.storyboard的圖像。如果任何人都可以在這裏協助,那麼這將是一個巨大的幫助,至少在2小時內一直在解決問題。感謝大家!

http://i.imgur.com/QCuJojA.png

+0

你不知何故取消設置類的故事板第二VC的,所以它試圖加載普通'UIViewController',這當然沒有名爲'nextButton'的屬性。或者,如果你沒有解除課程,那麼你必須從第二個VC中刪除'nextButton'插座。 – NRitH

+0

您能否包括堆棧跟蹤的截圖(日誌輸出在異常之上)? 我的直覺是告訴你擺脫故事板並跑步;這是一個糟糕的工具,長期限制你。如果你開始使用它,請包括堆棧跟蹤,我們會看到我們可以做什麼。 – Ryan

+0

嘿傢伙。非常感謝你的幫助。我自己動手修理。發現我刪除了它,但它仍在代碼中。再次感謝! –

回答

0

嘗試一下本作斯威夫特3

enter image description here

public func settingAction(_sender: UIButton) { 
    let settingStoryboard : UIStoryboard = UIStoryboard(name: "SettingViewController", bundle: nil) 
    let settingVC = settingStoryboard.instantiateViewController(withIdentifier: "SettingViewController") as! SettingViewController 
    self.present(settingVC, animated: true, completion: { 

    }) 
}