ios - Swift unexpectedly found nil while unwrapping an Optional value in TableView -
i know question asked many times,but not getting hint or answer those.actually new in swift.i created viewcontrollerr subclass of uitableviewcontroller
.when click on table row or cell in didselectrowatindexpath
method getting error fatal error: unexpectedly found nil while unwrapping optional value
. trying push viewcontroller.
class sidemenucontroller: uitableviewcontroller { override func viewdidload() { super.viewdidload() } override func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { print("row \(indexpath.row) selected") switch indexpath.row { case 0: break case 1: let vc = addvaluevc(nibname: "addvaluevc", bundle: nil) //following line giving error self.navigationcontroller!.pushviewcontroller(vc, animated: false) break default: break } } }
since not using uinavigationviewcontroller
, should replace line
self.navigationcontroller!.pushviewcontroller(vc, animated: false)
with this:
self.presentviewcontroller(vc, animated: false, completion: nil)
Comments
Post a Comment