Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
447 views
in Technique[技术] by (71.8m points)

uiviewcontroller - open viewcontroller from tab like in instagram camera page on IOS

what i want is suppose to be simple, instagram middle tab on IOS opens the app's camera interface but not like the rest of the tabs but as an independet view controller and when you press cancel it gets back to the last tab youv'e been.

any ideas??

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Edit: In order for this code to work you'll need to subclass UITabBarController and implement the UITabBarDelegate. So you'll add something like this:

@interface MyTabsViewController : UITabBarController <UITabBarDelegate>

In Interface Builder you'll need to set the tags of your tab items to whatever you need them to be:

enter image description here

And now you can do something like this:

-(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
    if(item.tag == 1)
    {
        [self presentViewController:myVC animated:YES completion:nil];
    }
    else if(item.tag == 2)
    {
       //your code
    }
}

This will allow you to get the tapped event for each of your tab bar items and do add some custom code, you just need to add the appropriate tags to your tab buttons in interface builder. For example, you could add code to show your own view controller as shown above.

Hope that helps!

And here's another link: How can i get Tabbar Item Button's Click event by clicking on TabbarItem button?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...