Hello there!
I am currently facing a relatively big problem of mine, and I can't seem to figure it out. You see, I am currently displaying data from my user defaults in my table view, and when I click one of these items - I get an error like this:
fatal error: unexpectedly found nil while unwrapping an Optional value
This is the code I am using;
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "selected" {
let VC5 : ViewControllerFive = segue.destinationViewController as! ViewControllerFive
let indexPath = self.tableView.indexPathForSelectedRow
if let nText = self.myDefs.objectForKey("Name")?.objectAtIndex(indexPath!.row) as? String{
VC5.tText = "Your name: " + nText
}
self.tableView.deselectRowAtIndexPath(indexPath!, animated: true)
}
This seemed to work for about a week ago, until I decided to re-design my user interface completely. If it's relevant, I can also post the other code related to my table view:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if let defs = myDefs.objectForKey("Name") {
return defs.count
} else {
return 0
}
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! TableViewCell
if let label = cell.prevText{
label.text = self.myDefs.valueForKey("Name")?.objectAtIndex(indexPath.row) as? String
}
}
return cell
}
Help would be greatly appreciated!