ios - How to navigate To a ViewController From xib file of a UIView Class -
i have view in xib file contain buttons. want move viewcontroller when press button (@ibaction)
. have used below code
let storyboard : uistoryboard = uistoryboard(name: "main", bundle:nil) let nextviewcontroller = storyboard.instantiateviewcontrollerwithidentifier("about") as! aboutviewcontroller self.presentviewcontroller(nextviewcontroller, animated: true, completion: nil)
i getting error "value of type 'slidemenuview' has no member 'presentviewcontroller'.
because class uiview type :
class slidemenuview: uiview { }
so how can navigate other view controller.
that beacuase class trying present uiview
, not uiviewcontroller
. has no present method.
i'm guessing view (slidemenuview) embedded inside viewcontroller. need implement delegate, , inform containing viewcontroller present next viewcontroller.
code below:
@protocol slidemenuviewdelegate: class { func slidemenuviewaboutbuttonclicked(menuview: slidemenuview) class slidemenuview: uiview { weak var delegate: slidemenuviewdelegate? @ibaction func aboutbuttonclicked(sender: anyobject) { self.delegate?.slidemenuviewaboutbuttonclicked(self) }
now, in viewcontroller, implement delegate method:
func slidemenuviewaboutbuttonclicked(menuview: slidemenuview) { let storyboard : uistoryboard = uistoryboard(name: "main", bundle:nil) let nextviewcontroller = storyboard.instantiateviewcontrollerwithidentifier("about") as! aboutviewcontroller self.presentviewcontroller(nextviewcontroller, animated: true, completion: nil) }
also, dont forget assign slidermenuview object viewcontroller delegate. like:
self.slidermenuview.delegate = self // (self == containing viewcontroller
Comments
Post a Comment