【发布时间】:2015-08-31 01:26:48
【问题描述】:
我在我的项目中使用 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)
}
}
【问题讨论】: