ios - Viewcontroller is not instantiating to Home VC when pressing login button -
when login app home viewcontoller
not appear , gives error unexpectedly found nil while unwrapping optional. irrates me there no syntax error found.
login view controller
@ibaction func loginaction(_ sender: any) { let vc : uiviewcontroller = self.storyboard?.instantiateviewcontroller(withidentifier: "viewcontroller") as! viewcontroller self.present(vc, animated: true, completion: nil) }
home view controller
import uikit class viewcontroller: uiviewcontroller { @iboutlet weak var mainhomebutton: uibarbuttonitem! override func viewdidload() { super.viewdidload() mainhomebutton.target = swrevealviewcontroller() mainhomebutton.action = #selector(swrevealviewcontroller.revealtoggle(_:)) self.view.addgesturerecognizer(self.revealviewcontroller().pangesturerecognizer()) } }
check if swrevealviewcontroller not nil on viewdidload()
if self.revealviewcontroller() != nil { mainhomebutton.target = self.revealviewcontroller() mainhomebutton.action = #selector(swrevealviewcontroller.revealtoggle(_:)) self.view.addgesturerecognizer(self.revealviewcontroller().pangesturerecognizer()) }
update
your storyboard structure need revised. should present swrevealviewcontroller
on login button click, not view controller.
in storyboard segue should link this:
- login button -> swrevealviewcontroller
- swrevealviewcontroller (sw_front) -> navigation controlller of home vc
- swrevealviewcontroller (sw_rear) -> menu controller
hope helps. happy coding :)
Comments
Post a Comment