s中将UITabbarController添加到UIViewCo

s中将UITabbarController添加到UIViewCo

本文介绍了如何在iOs中将UITabbarController添加到UIViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用TabbarController推送Viewcontroller?在Viewcontroller'XIB中,我创建了UITabbarController。然后我推这个ViewController,但它没有出现UITabbarController。
这是我的代码:
* Viewcontroller.h:

How to push Viewcontroller with TabbarController? In Viewcontroller'XIB, i created UITabbarController. Then i push this ViewController, but it not appear UITabbarController.This is my code:*Viewcontroller.h:

 @interface StatusViewController : UIViewController<UITabBarControllerDelegate>
{
    IBOutlet UITabBarController *tabBarController;

    IBOutlet UIButton *UploadButton;
    IBOutlet UIButton *ConvertorButton;
    IBOutlet UIButton *CompletedButton;
}
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@end

* Viewcontroller.m:

*Viewcontroller.m:

@implementation StatusViewController
@synthesize tabBarController ;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization

    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self createTabView];
}
-(void)createTabView
{
    ....

    ....
    [ConvertorButton addSubview:Label3];

    [CompletedButton setTag:3];


    [CompletedButton setImage:[UIImage imageNamed:@"Overlay-2.png"] forState:UIControlStateNormal];
    [CompletedButton setImage:[UIImage imageNamed:@"background.jpg"] forState:UIControlStateSelected];
    [CompletedButton setImage:[UIImage imageNamed:@"background.jpg"] forState:UIControlStateHighlighted];

    //[[CompletedButton layer] setBorderWidth:2.0f];
    // [[CompletedButton layer] setBorderColor:[UIColor grayColor].CGColor];

    UILabel *Label4=[[UILabel alloc]initWithFrame:CGRectMake(6, 8, 70, 30)];
    [Label4 setTextAlignment:UITextAlignmentCenter];
    [Label4 setText:@"Completed"];


    Label4.backgroundColor=[UIColor clearColor];
    [Label4 setFont:[UIFont fontWithName:@"Helvetica-Bold" size:12]];
    Label4.textColor=[UIColor whiteColor];
    [CompletedButton addSubview:Label4];

    // [self selectTab:1];

    [self.view addSubview:UploadButton];

    [self.view addSubview:ConvertorButton];

    [self.view addSubview:CompletedButton];


}

感谢您的帮助

推荐答案

如果你想在你的UIViewController类中使用UITabBarController,那么使用下面的代码......

If You want to use UITabBarController in your UIViewController class then use this below code...

UIViewController .h类 -

UIViewController .h Class -

    @property (nonatomic, retain) UITabBarController *tab;

UIViewController .m类 -

UIViewController .m Class -

添加这在ViewDidLoad方法中......

Add this in ViewDidLoad method...

    self.tab=[[UITabBarController alloc]init];

    // FirstViewController
    First *fvc=[[First alloc]initWithNibName:nil bundle:nil];
    fvc.title=@"First";
    fvc.tabBarItem.image=[UIImage imageNamed:@"i.png"];

    //SecondViewController
    Second *svc=[[Second alloc]initWithNibName:nil bundle:nil];
    svc.title=@"Second";
    svc.tabBarItem.image=[UIImage imageNamed:@"im.png"];

    //ThirdViewController
    Third *tvc=[[Third alloc]initWithNibName:nil bundle:nil];
    tvc.title=@"Third";
    tvc.tabBarItem.image=[UIImage imageNamed:@"img.png"];

    self.tab.viewControllers=[NSArray arrayWithObjects:fvc, svc, tvc, nil];

    [self.view addSubview:self.tab.view];

这里First,Second和Third是三个不同的UIViewControllers。并且你不需要在标签上给出动作。

here First, Second and Third are three different UIViewControllers. And you don't need to give the action on Tabs.

它会起作用......

It will work...

这篇关于如何在iOs中将UITabbarController添加到UIViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 12:08