首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Koloda委托:致命错误:在展开可选值时意外发现nil

Koloda委托:致命错误:在展开可选值时意外发现nil
EN

Stack Overflow用户
提问于 2015-08-31 09:26:48
回答 1查看 677关注 0票数 2

我在我的项目中使用Koloda,每当我试图加载一个视图控制器时,我都会在kolodaView.dataSource = self上得到错误“致命错误:在打开可选值时意外发现了nil”,然后如果它被注释掉了,我就会在kolodaView.delegate = self上得到同样的错误。我是IOS和Swift的新手,所以我不确定到底是怎么回事。下面是Koloda viewcontroller中的代码显示错误的地方:

代码语言:javascript
复制
 override func viewDidLoad() {
    super.viewDidLoad()

    kolodaView.dataSource = self
    kolodaView.delegate = self

    self.modalTransitionStyle = UIModalTransitionStyle.FlipHorizontal
}

下面是我试图加载的UIViewController中的代码。它们也不是通过任何segues链接的。

代码语言:javascript
复制
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)

}
}
EN

回答 1

Stack Overflow用户

发布于 2015-08-31 09:42:18

kolodaView实例为空。通过将NSLog放在super.viewDidLoad()后面来验证这一点。

代码语言:javascript
复制
NSLog("kolodaView  \(kolodaView)");

我认为,您的IBOutlet连接不正确。你得看看这个。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32302831

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档