如何在 iphone 中调用 UITabbarController 类上的右栏按钮项
我以编程方式创建了一个继承自 UITabBarController 的选项卡栏类。
这是我的代码:
#import <UIKit/UIKit.h>
@class JourneyAppDelegate;
@interface TTabBar :UITabBarController<UITabBarControllerDelegate> {
UITabBarController *mTabController;
JourneyAppDelegate *app;
}
#import "TTabBar.h"
#import "TAddNewJourney.h"
#import "TJourneylistController.h"
#import "TAppStoreController.h"
#import "TSettingsController.h"
#import "TAboutController.h"
#import "TReviewsController.h"
#import "JourneyAppDelegate.h"
@implementation TTabBar
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization.
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
-(void)Add
{
app= (JourneyAppDelegate*)[[UIApplication sharedApplication]delegate];
TAddNewJourney *j=[[TAddNewJourney alloc]init];
[app.navigationController pushViewController:j animated:YES];
[j release];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonSystemItemDone target:self action:nil];
TJourneylistController *journeylist =[[TJourneylistController alloc]initWithNibName:nil bundle:nil];
//UINavigationController *journeylistnavigation =[[UINavigationController alloc]initWithRootViewController:journeylist];
//this is to provide the right navigation button item
UIBarButtonItem *addButton = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(Add)] autorelease];
self.navigationItem.rightBarButtonItem = addButton;
[journeylist.tabBarItem initWithTitle:@"Journey List" image:[UIImage imageNamed:@"newJourney.png"] tag:1];
journeylist.navigationItem.title =@"Journey List";
//[journeylist release];
TAppStoreController *appstore =[[TAppStoreController alloc]initWithNibName:nil bundle:nil];
//UINavigationController *appstorenavigation =[[UINavigationController alloc]initWithRootViewController:appstore];
[appstore.tabBarItem initWithTitle:@"App Store" image:[UIImage imageNamed:@"appStore.png"] tag:2];
appstore.navigationItem.title = @"App Store";
//[appstore release];
TSettingsController *settings =[[TSettingsController alloc]initWithNibName:nil bundle:nil];
//UINavigationController *settingsnavigation =[[UINavigationController alloc]initWithRootViewController:settings];
[settings.tabBarItem initWithTitle:@"Settings" image:[UIImage imageNamed:@"settings.png"] tag:3];
settings.navigationItem.title = @"Settings";
//[settings release];
TAboutController *about =[[TAboutController alloc]initWithNibName:nil bundle:nil];
//UINavigationController *aboutnavigation =[[UINavigationController alloc]initWithRootViewController:about];
[about.tabBarItem initWithTitle:@"About" image:[UIImage imageNamed:@"contactUs.png"] tag:4];
about.navigationItem.title =@"About Us";
// [about release];
NSArray *controllers = [NSArray arrayWithObjects:journeylist,appstore,settings,about,nil];
//self.viewControllers = controllers;
self.viewControllers = controllers;
//[controllers release];
}
i need a right navigation item on the class Journeylistcontroller.So i have added it to the code but the problem is the navigtaion item gets set to the four controllers.i need that only journeylistcontroller should have the navigation item.Please can anybody help me in solving this problem.Thanks
I Have programatically created a tabbar class which inherits from UITabBarController.
This is my code:
#import <UIKit/UIKit.h>
@class JourneyAppDelegate;
@interface TTabBar :UITabBarController<UITabBarControllerDelegate> {
UITabBarController *mTabController;
JourneyAppDelegate *app;
}
#import "TTabBar.h"
#import "TAddNewJourney.h"
#import "TJourneylistController.h"
#import "TAppStoreController.h"
#import "TSettingsController.h"
#import "TAboutController.h"
#import "TReviewsController.h"
#import "JourneyAppDelegate.h"
@implementation TTabBar
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
/*
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization.
}
return self;
}
*/
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView {
}
*/
-(void)Add
{
app= (JourneyAppDelegate*)[[UIApplication sharedApplication]delegate];
TAddNewJourney *j=[[TAddNewJourney alloc]init];
[app.navigationController pushViewController:j animated:YES];
[j release];
}
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonSystemItemDone target:self action:nil];
TJourneylistController *journeylist =[[TJourneylistController alloc]initWithNibName:nil bundle:nil];
//UINavigationController *journeylistnavigation =[[UINavigationController alloc]initWithRootViewController:journeylist];
//this is to provide the right navigation button item
UIBarButtonItem *addButton = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(Add)] autorelease];
self.navigationItem.rightBarButtonItem = addButton;
[journeylist.tabBarItem initWithTitle:@"Journey List" image:[UIImage imageNamed:@"newJourney.png"] tag:1];
journeylist.navigationItem.title =@"Journey List";
//[journeylist release];
TAppStoreController *appstore =[[TAppStoreController alloc]initWithNibName:nil bundle:nil];
//UINavigationController *appstorenavigation =[[UINavigationController alloc]initWithRootViewController:appstore];
[appstore.tabBarItem initWithTitle:@"App Store" image:[UIImage imageNamed:@"appStore.png"] tag:2];
appstore.navigationItem.title = @"App Store";
//[appstore release];
TSettingsController *settings =[[TSettingsController alloc]initWithNibName:nil bundle:nil];
//UINavigationController *settingsnavigation =[[UINavigationController alloc]initWithRootViewController:settings];
[settings.tabBarItem initWithTitle:@"Settings" image:[UIImage imageNamed:@"settings.png"] tag:3];
settings.navigationItem.title = @"Settings";
//[settings release];
TAboutController *about =[[TAboutController alloc]initWithNibName:nil bundle:nil];
//UINavigationController *aboutnavigation =[[UINavigationController alloc]initWithRootViewController:about];
[about.tabBarItem initWithTitle:@"About" image:[UIImage imageNamed:@"contactUs.png"] tag:4];
about.navigationItem.title =@"About Us";
// [about release];
NSArray *controllers = [NSArray arrayWithObjects:journeylist,appstore,settings,about,nil];
//self.viewControllers = controllers;
self.viewControllers = controllers;
//[controllers release];
}
i need a right navigation item on the class Journeylistcontroller.So i have added it to the code but the problem is the navigtaion item gets set to the four controllers.i need that only journeylistcontroller should have the navigation item.Please can anybody help me in solving this problem.Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只需要在一个视图中显示栏按钮项,则为该视图控制器创建一个 navigationController 和 Journeylistcontroller,然后将创建的 navigationController 添加到数组中。
另外,您需要将 rightbarbutton 项目添加到创建的导航控制器而不是 self.navigationController 中。
编辑:
尝试这个,还将navController添加到数组而不是旅程列表中
if you need to display barbutton item in only one view, then create a navigationController and Journeylistcontroller to that view controller and then, add created navigationcontroller to the array.
Also, u need to add rightbarbutton item to the created navigation controller not to self.navigationController.
Edit:
try this , also add navController to array not journeylist