編輯 - 這不是重複的。即使所有連接都正確,我仍然有這個錯誤。糾正這個問題的措施顯然需要按照特定的順序完成。請參閱標記爲答案的回覆。該類不是密鑰編碼密鑰的關鍵值(我更改了Storyboard中的文件名)
我改變了故事板中的文件名,一切都打破了。我得到錯誤「這個類不是關鍵的值編碼密鑰」,但我不認爲這實際上是問題。我有一個名爲Draft的viewcontroller和另一個名爲Draft2的viewcontroller。在我的故事板上,我將草稿名稱從草稿更改爲草稿3,然後將草稿2更改爲草稿。我分別更改了類的名稱,然後刪除了segues並重新創建它們。我也分別更改了視圖控制器的標題和故事板ID。我真的不在乎Draft3,因爲它最終會被刪除,但我需要草案(新版本)的工作。
我重新連接了名爲Draft的新ViewController的所有插座。我也試過清理程序(cmd + shift + k)。我試過保存和關閉。
這是怎麼回事?
這是我的草案的一部分的viewController
class Draft: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout, UISearchBarDelegate {
@IBOutlet weak var battlegroundName: UILabel!
@IBOutlet weak var draftStatus: UILabel!
@IBOutlet weak var draftNotes: UILabel!
@IBOutlet weak var collectionHeroPool: UICollectionView!
@IBOutlet weak var collectionTeam1Bans: UICollectionView!
@IBOutlet weak var collectionTeam2Bans: UICollectionView!
@IBOutlet weak var collectionTeam1Picks: UICollectionView!
@IBOutlet weak var collectionTeam2Picks: UICollectionView!
@IBAction func undoButton(sender: AnyObject) {
self.navigationController?.popViewControllerAnimated(true)
self.navigationController?.navigationBarHidden = false
//dismissViewControllerAnimated(false, completion: nil)
}
var team1First = true
var battleground: Battleground!
var team1 = [Hero]()
var team2 = [Hero]()
var turn = 1
var team1Active = true
var activeTeam = [Hero]()
var team1Bans = [Int: Hero]()
var team2Bans = [Int: Hero]()
var team1Picks = [Int: Hero]()
var team2Picks = [Int: Hero]()
var bans1 = [1,9]
var bans2 = [2,8]
var picks1 = [3, 6, 7, 12, 13]
var picks2 = [4, 5, 10, 11, 14]
var pickedHeroes = [Hero]()
override func viewDidLoad() {
super.viewDidLoad()
let value = UIInterfaceOrientation.LandscapeLeft.rawValue
UIDevice.currentDevice().setValue(value, forKey: "orientation")
self.navigationController?.navigationBarHidden = true
battlegroundName.text = battleground.name
此代碼是在我的新秀訓練是塞格斯草稿
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "preDraftToDraft3" {// if this is the segue being loaded with this identifier
if let detailsVC = segue.destinationViewController as? Draft3 { // grab the view control we will go to and cast it as the hero detail class
detailsVC.team1First = team1First!
//print(selectedMap!.name)
detailsVC.battleground = selectedMap
//print(detailsVC.battleground.name)
}
}
if segue.identifier == "preDraftToDraft" {// if this is the segue being loaded with this identifier
if let detailsVC = segue.destinationViewController as? Draft { // grab the view control we will go to and cast it as the hero detail class
detailsVC.team1First = team1First!
//print(selectedMap!.name)
detailsVC.battleground = selectedMap
//print(detailsVC.battleground.name)
}
}
}
@IBAction func startDraft(sender: AnyObject) {
if team1First != nil && selectedMap != nil {
performSegueWithIdentifier("preDraftToDraft", sender: nil)
}
}
謝謝,這工作,我從來沒有想到,有一個「必要的」順序。 – Apple