0

我想在顶部有标签栏。

所以我在 XCode 中创建了一个新项目。添加了一个视图,然后在该视图中我添加了(滚动条、文本和另一个视图)。见图片。

MainWindow 的情节提要视图。 顶部是标签主机,中间是内容,底部是版权

我想要的是让我的标签栏在顶部。然后在中间是标签栏的内容,下面是一个小的版权文本。见图片。

我在 StoryBoard 中添加的所有控件

不知道如何正确地做到这一点。我试图动态创建 UITabBarController,然后将其分配到顶部的视图中。(图片上的顶部空白区域专用于标签栏)。

这是我初始化 MainWindow 的代码。

主窗口.h

#import <UIKit/UIKit.h>

@class Intro;

@interface MainWindow : UIViewController
@property (strong, nonatomic) IBOutlet UIScrollView *mainContentFrame;
@property (strong, nonatomic) IBOutlet UIView *mainTabBarView;
@property (strong, nonatomic) UITabBarController *mainTabBar;

@property (nonatomic, strong) Intro *intro; // Trying to get this tab to show in the tab bar

@end

主窗口.m

#import "MainWindow.h"
#import "Intro.h"

@interface MainWindow ()

@end

@implementation MainWindow
@synthesize mainContentFrame = _mainContentFrame;
@synthesize mainTabBarView = _mainTabBarView;
@synthesize mainTabBar = _mainTabBar;

@synthesize intro = _intro;

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

- (void)viewDidLoad
{
    _intro = [[Intro alloc] init];
    NSArray *allViews = [[NSArray alloc] initWithObjects:_intro, nil];

    [super viewDidLoad];
    // Do any additional setup after loading the view.

    _mainTabBar = [[UITabBarController alloc] init];
    [_mainTabBar setViewControllers:allViews];

    [_mainTabBarView.window addSubview:_mainTabBar.tabBarController.view];
}

- (void)viewDidUnload
{
    [self setMainTabBar:nil];
    [self setMainContentFrame:nil];
    [self setMainContentFrame:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

我缺少什么让这个工作?希望内容最终出现在滚动视图中,以便所有选项卡都可以滚动。

4

1 回答 1

0

iOS 用户界面指南说 UITabBar 必须在 ViewController 的底部。您应该为这种视图创建自己的 GUI 或使用“老式”方式。我不会尝试绕过 UITabBar,因为您的应用程序可能会被 Apple 拒绝。

于 2012-07-13T09:51:11.143 回答