ios - Is it possible for a button to open into a specific tab when using the Tab Bar Controller? -
the question little confusing articulate image little more helpful. here's setup:
so, want first view button open firstviewcontroller
, , want second view button open secondviewcontroller
. if link second view button secondviewcontroller
this:
i lose tab navigation. , if connect button tabviewcontroller
this:
then automatically open firstviewcontroller
. unless i'm missing something, seems need done little code cannot seem find explains how this.
thank you!
create storyboard segue viewcontroller
tabbarcontroller
identifier. assign selelctedindex
value of tabbarcontroller in prepareforsegue
method
@ibaction func firstbtnaction(_ sender: any) { (sender as! uibutton).tag = 0 performsegue(withidentifier: "tabbar", sender: sender) } @ibaction func secbtnaction(_ sender: any) { (sender as! uibutton).tag = 1 performsegue(withidentifier: "tabbar", sender: sender) } override func prepare(for segue: uistoryboardsegue, sender: any?) { if segue.identifier == "tabbar" { if let vc = segue.destination as? uitabbarcontroller { vc.selectedindex = (sender as! uibutton).tag } } }
Comments
Post a Comment