ios - How to perform different segue based on condition from a button click in swift? -
i'm building app in button takes profile registry view if open app first time , if open app other time. how can accomplish programmatically, have seen connects button 1 view.
@ibaction func nextviewcontroller(_ sender: uibutton) { if launchedbefore { print("not first launch.") } else { print("first launch, setting userdefault.") userdefaults.standard.set(true, forkey: "launchedbefore") } }
i think, trying connect button perform segue multiple viewcontroller right?? not possible
instead have connect segue between view controllers
adding segue between 2 viewcontrollers:
from interface builder, ctrl + drag between 2 viewcontrollers want link. should see:
and based on condition should perform segue identifiers below:
@ibaction func nextviewcontroller(_ sender: uibutton) { if launchedbefore { /*use identifier given in story board*/ self.performsegue(withidentifier: "othervc", sender: self) } else { /*use identifier given in story board*/ self.performsegue(withidentifier: "register", sender: self)) userdefaults.standard.set(true, forkey: "launchedbefore") } }
for more descriptive answer segue see answer how connect 2 view controllers 1 button in storyboard?
Comments
Post a Comment