ios - How do I change the initial tab bar selection in swift? -
in trying find solution came across answer:
[ https://stackoverflow.com/a/10441200/4856759 ]
it seems accomplish want to, in objective c:
uitabbarcontroller *tabbar = (uitabbarcontroller *)self.window.rootviewcontroller; tabbar.selectedindex = 0;
how do in swift? first attempt returns error:
cannot convert expression's type '$t4??' type 'uitabbarcontroller'
var tabbar: uitabbarcontroller = self.window?.rootviewcontroller tabbar.selectedindex = 1
worked me! need add as! uitabbarcontroller
:
var tabbar: uitabbarcontroller = self.window?.rootviewcontroller as! uitabbarcontroller tabbar.selectedindex = 1
Comments
Post a Comment