帮助显示 UITabBarController

发布于 2024-10-31 00:48:24 字数 1933 浏览 0 评论 0原文

我为我的应用程序创建了一个自定义 Tabbarcontroller。现在我有一个 uiview,在底部我想显示我的 tabviewcontroller 而不选择任何按钮。当用户按下任何按钮时,它将加载所选选项卡栏项目的相应视图。不知怎的,我的下面的代码不起作用。它显示一个白色屏幕来代替我的 uiview 屏幕,并且底部不显示选项卡栏。

#import <UIKit/UIKit.h>
#import "UICustomTabViewController.h"

@interface AssignmentViewController : UIViewController<UITabBarDelegate, UITableViewDelegate,UITableViewDataSource> {
    NSMutableArray *listAssignments;
    NSMutableArray *staffImages;
    UICustomTabViewController *tabViewController;
    }

@property (nonatomic, retain) UICustomTabViewController *tabViewController;

@end
- (void)viewDidLoad {


    UICustomTabViewController *tvController = [[UICustomTabViewController alloc] initWithNibName:@"TabViewController" bundle:nil];

    self.tabViewController = tvController;  

    [self.view addSubview:tvController.view];

    listAssignments = [[NSMutableArray alloc] init];
    staffImages = [[NSMutableArray alloc] init];

    //Add items
    [listAssignments addObject:@"TRANSPORTATION"];
    [listAssignments addObject:@"ROOMS"];
    [listAssignments addObject:@"FOOD & BEVERAGES"];

    //Set the title
    self.navigationItem.title = @"ASSIGNMENTS";

    [super viewDidLoad];
         [tvController release];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    tableView.separatorColor=[UIColor grayColor];
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }


    // Configure the cell.
    cell.textLabel.textColor=[UIColor blackColor];
    cell.textLabel.text=[listAssignments objectAtIndex:indexPath.row];
    cell.textLabel.font=[UIFont systemFontOfSize:16];   
    return cell;
}

i have created a custom Tabbarcontroller for my application. now i have a uiview where at the bottom i want to display my tabviewcontroller without any buttons selected. And when the user presses on any button it will then load the corresponding view of the tabbar item selected. Somehow my below code doesnt work. it displays a white screen in place of my uiview screen and doesnt display a tabbar at the bottom.

#import <UIKit/UIKit.h>
#import "UICustomTabViewController.h"

@interface AssignmentViewController : UIViewController<UITabBarDelegate, UITableViewDelegate,UITableViewDataSource> {
    NSMutableArray *listAssignments;
    NSMutableArray *staffImages;
    UICustomTabViewController *tabViewController;
    }

@property (nonatomic, retain) UICustomTabViewController *tabViewController;

@end
- (void)viewDidLoad {


    UICustomTabViewController *tvController = [[UICustomTabViewController alloc] initWithNibName:@"TabViewController" bundle:nil];

    self.tabViewController = tvController;  

    [self.view addSubview:tvController.view];

    listAssignments = [[NSMutableArray alloc] init];
    staffImages = [[NSMutableArray alloc] init];

    //Add items
    [listAssignments addObject:@"TRANSPORTATION"];
    [listAssignments addObject:@"ROOMS"];
    [listAssignments addObject:@"FOOD & BEVERAGES"];

    //Set the title
    self.navigationItem.title = @"ASSIGNMENTS";

    [super viewDidLoad];
         [tvController release];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    tableView.separatorColor=[UIColor grayColor];
    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
    }


    // Configure the cell.
    cell.textLabel.textColor=[UIColor blackColor];
    cell.textLabel.text=[listAssignments objectAtIndex:indexPath.row];
    cell.textLabel.font=[UIFont systemFontOfSize:16];   
    return cell;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

街道布景 2024-11-07 00:48:24

UITabBarController 应该是你的父级。尝试将您的 navigationController 添加到您希望其显示的选项卡上的 tvControllers 子视图。 tvController.views = [NSArray arrayWithObjects:navigationController, someOtherController, nil];

要显示 tableView,请将 tableView 添加到 navigationController 的视图中。

UITabBarController should be your parent. Try to add your navigationController to your tvControllers subview at the tab you want it to show. tvController.views = [NSArray arrayWithObjects:navigationController, someOtherController, nil];

To show a tableView, you add the tableView to your navigationController's view.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文