我在我的项目中使用Koloda,每当我试图加载一个视图控制器时,我都会在kolodaView.dataSource = self上得到错误“致命错误:在打开可选值时意外发现了nil”,然后如果它被注释掉了,我就会在kolodaView.delegate = self上得到同样的错误。我是IOS和Swift的新手,所以我不确定到底是怎么回事。下面是Koloda viewcontroller中的代码显示错误的地方:
override func viewDidLoad() {
super.viewDidLoad()
kolodaView.dataSource = self
kolodaView.delegate = self
self.modalTransitionStyle = UIModalTransitionStyle.FlipHorizontal
}下面是我试图加载的UIViewController中的代码。它们也不是通过任何segues链接的。
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)
}
}发布于 2015-08-31 09:42:18
kolodaView实例为空。通过将NSLog放在super.viewDidLoad()后面来验证这一点。
NSLog("kolodaView \(kolodaView)");我认为,您的IBOutlet连接不正确。你得看看这个。
https://stackoverflow.com/questions/32302831
复制相似问题