在Objective-C的视图中单击按钮后,如何按下标签栏控制器? [英] How can I push tab bar controller after click a button from a view in Objective-C?

查看:88
本文介绍了在Objective-C的视图中单击按钮后,如何按下标签栏控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在视图中有一个按钮,我想在单击按钮后添加标签栏控制器.我该怎么办?

I have a button in a view, I want to add tab bar controller after click the button. How can I do this?

推荐答案

首先,我不认为将标签栏作为子视图推送是一个好主意

first of all, i don't think pushing a tab bar as a subview as a good idea

但是如果您仍然想这样做,有很多方法可以解决

but if you still want to do this, there's a lot of way to work around

其中之一是通过使用modalview

one of them is by using modalview

首先,您必须在点击按钮后添加此代码

first you have to add this code after you make the button

[button addTarget:self action:@selector(buttonTapped:) forControlEvents:UIControlEventTouchUpInside];

将事件监听器附加到您拥有的按钮上

it attach an event listener to the button you have

接下来,您使事件功能可以执行标签栏推送

next, you make the event function to do the tab bar pushing

-(void)buttonTapped: (UIButton *)sender
{
        YourTabBarClass *myTabBar = [[YourTabBarClass alloc]initWithNibName:nil bundle:nil];
        myTabBar.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

        [self presentModalViewController:myTabBar animated:YES];
}

并且不要忘记在您的.m文件中导入tabbarcontroller类的头文件

and dont forget to import the tabbarcontroller class header file in your .m

#import "YourTabBarClass.h"

希望获得帮助;)

edit:如果您需要从标签栏视图返回到上一菜单,则可以添加按钮,为其提供事件监听器,并将此代码放入函数中

edit : if you need to go back from the tab bar view into the previous menu, you can add a button, give it an event listener, and put this code inside the function

[self resignFirstResponder];
    [self dismissModalViewControllerAnimated:YES];

这篇关于在Objective-C的视图中单击按钮后,如何按下标签栏控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆