2

I am using Koloda in my project and whenever I try to load one view controller in particular I get the error "fatal error: unexpectedly found nil while unwrapping an Optional value" on the kolodaView.dataSource = self and then if that is commented out I get the same error on kolodaView.delegate = self. I am fairly new to IOS and Swift so I am not sure what is going on. The following is where the code in the Koloda viewcontroller is showing the error:

 override func viewDidLoad() {
    super.viewDidLoad()

    kolodaView.dataSource = self
    kolodaView.delegate = self

    self.modalTransitionStyle = UIModalTransitionStyle.FlipHorizontal
}

The following is the code from the UIViewController that I am trying to load. They are also not linked via any 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)

}
}
Ryguyu
  • 173
  • 14

1 Answers1

0

kolodaView instance is nil. verify this by putting NSLog right after super.viewDidLoad().

NSLog("kolodaView  \(kolodaView)");

I think, you have not connected your IBOutlet properly. you need to check this out.

Shoaib
  • 2,286
  • 1
  • 19
  • 27
  • I reconnected the `IBOutlet` and am still getting a nil error. It is also worth noting that when I try and load the `koloda viewController` that everything works fine. It's just when I load the other `view controller` when I run into problems. – Ryguyu Aug 31 '15 at 01:51
  • You may want to refer to this question: https://stackoverflow.com/questions/40607951/how-to-instantiate-a-view-controller-programatically-without-storyboard – Chace Nov 26 '17 at 19:21