Thiha Aung
Thiha Aung

Reputation: 5106

Fatal error: unexpectedly found nil while unwrapping an Optional value (lldb)

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {
    if segue.identifier == "showLocalMenuDetail" {
        if let indexPath = self.tableView.indexPathForSelectedRow() {
            self.slideMenuController()?.closeLeft()
            let destinationController = segue.destinationViewController as DetailViewController
            destinationController.localMenuImage = self.locals[indexPath.row].image
            destinationController.localMenuTitle = self.locals[indexPath.row].title

    } }
}

I got the error at this "self.tableView.indexPathForSelectedRow()".I am navigating to other view controller using slide out navigation panel like facebook using segue and embeded navigation controller on left menu.

I don't know what is wrong with it,Please help!

Upvotes: 3

Views: 7745

Answers (1)

GoZoner
GoZoner

Reputation: 70275

Such errors occur when you attempt to access the value of a variable declared as an 'Implicitly Unwrapped Optional' (that is, declared with a !) but when that variable is unbound (bound to nil).

In your case, the crash occurs because in a UITableViewController the tableView property is defined as:

var tableView: UITableView!

It is an implicitly unwrapped optional. If it is unbound, crash.

You've not bound tableView within Xcode's Interface Builder to your UITableViewController. In Xcode, if you look at your controller in the 'Connections Inspector' you will find under 'Outlets' that 'view' is not bound. Thus, the expression self.tableView will produce a runtime crash.

Upvotes: 4

Related Questions