Ios Koloda委托:致命错误:在展开可选值时意外发现nil
我在我的项目中使用Koloda,每当我尝试加载一个视图控制器时,我都会在Ios Koloda委托:致命错误:在展开可选值时意外发现nil,ios,swift,Ios,Swift,我在我的项目中使用Koloda,每当我尝试加载一个视图控制器时,我都会在kolodaView.dataSource=self上得到错误“致命错误:在展开可选值时意外发现零”,然后如果这一错误被注释掉,我会在kolodaView.delegate=self上得到相同的错误。我对IOS和Swift还相当陌生,所以我不确定到底发生了什么。以下是Kolodaviewcontroller中的代码显示错误的地方: override func viewDidLoad() { super.viewDi
kolodaView.dataSource=self
上得到错误“致命错误:在展开可选值时意外发现零”,然后如果这一错误被注释掉,我会在kolodaView.delegate=self
上得到相同的错误。我对IOS和Swift还相当陌生,所以我不确定到底发生了什么。以下是Kolodaviewcontroller
中的代码显示错误的地方:
override func viewDidLoad() {
super.viewDidLoad()
kolodaView.dataSource = self
kolodaView.delegate = self
self.modalTransitionStyle = UIModalTransitionStyle.FlipHorizontal
}
以下是我试图加载的UIViewController
中的代码。它们也不通过任何分段链接
import Foundation
import UIKit
class genderSelection1: ViewController, UITableViewDelegate, UITableViewDataSource{
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.delegate = self
self.tableView.dataSource = self
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 2
}
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
let headerCell = tableView.dequeueReusableCellWithIdentifier("headerCell") as! UITableViewCell
headerCell.backgroundColor = UIColor.groupTableViewBackgroundColor()
return headerCell
}
func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! UITableViewCell
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
}
}
kolodaView实例为零。通过将NSLog放在super.viewDidLoad()之后来验证这一点
我想,你没有正确连接你的IB插座。您需要对此进行检查。我重新连接了
IBOutlet
,但仍然收到一个零错误。还值得注意的是,当我尝试加载koloda viewController
时,一切正常。当我加载另一个视图控制器时,我遇到了问题。您可能需要参考以下问题:
NSLog("kolodaView \(kolodaView)");