帮助显示 UITabBarController
我为我的应用程序创建了一个自定义 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.