5

如何使用 TabbarController 推送 Viewcontroller?在 Viewcontroller'XIB 中,我创建了 UITabbarController。然后我推送这个 ViewController,但它没有出现 UITabbarController。这是我的代码:*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

*视图控制器.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];


}

谢谢你的帮助

4

2 回答 2

9

如果你想在你的 UIViewController 类中使用 UITabBarController 然后使用下面的代码......

UIViewController .h 类 -

    @property (nonatomic, retain) UITabBarController *tab;

UIViewController .m 类 -

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

    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 是三个不同的UIViewController。而且您不需要在选项卡上执行操作。

它会工作...

于 2013-08-09T09:26:32.550 回答
1

如果您是初学者,最佳做法是在 google 中搜索最新的 api 示例,然后了解代码并创建自己的世界。

1) 你可以在这里找到苹果的相关示例代码。

2) TweetieBar -- 这是带有自定义 TabBarController(TweetieTabBar) 的示例代码

于 2013-08-09T09:00:51.530 回答