如何在UITabbar中的UINavigationbar上添加右键

时间:2011-11-08 08:55:17

标签: uinavigationcontroller uitabbar uitabbaritem

在uinavigationbar上添加右键时出现问题。我的笔尖组织者是这样的:

CustomTabViewController:UIViewController

- > CustomTableViewController1:UIViewController

- > CustomTableViewController2:UIViewController

CustomTabViewControllers位于Tabbar项目

我需要保存输入,我可以从导航控制器添加导航项,但是当他们是Tabbar项目中的孩子时,我无法从View Controller添加它们。 这是我的代码:

@interface CustomTabViewController : UIViewController <UITabBarDelegate> {
     NSArray *detailViews;
    IBOutlet UITabBar *tabBar;
    IBOutlet UITabBarItem *tabBarItem1;
    IBOutlet UITabBarItem *tabBarItem2;
    UIViewController *selectedViewController;

}

@property (nonatomic, retain) NSArray *detailViews;
@property (nonatomic, retain) IBOutlet UITabBar *tabBar;
@property (nonatomic, retain) IBOutlet UITabBarItem *tabBarItem1;
@property (nonatomic, retain) IBOutlet UITabBarItem *tabBarItem2;
@property (nonatomic, retain) UIViewController *selectedViewController;
@end

@implementation TabViewController

@synthesize detailViews;
@synthesize tabBar;
@synthesize tabBarItem1;
@synthesize tabBarItem2;
@synthesize selectedViewController;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil number:(NSString *)num{

    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {

        // Custom initialization
    CustomTableViewController1 *tVC1 = [[CustomTableViewController1 alloc]initWithNibName:@"CustomTableViewController1" bundle:nil];        
        CustomTableViewController2 *tVC2 = [[CustomTableViewController2 alloc]initWithNibName:@"CustomTableViewController2" bundle:nil];


        NSDictionary *detail = [[[Services sharedInstance] getDetail:num] copy];

        [tVC1 setDetail:detail];     
        [tVC2 setDetail:detail];
    NSArray *array = [[NSArray alloc] initWithObjects:tVC1, tVC2, nil];
    self.detailViews = array;
    [self.view addSubview:tVC1.view];
    self.selectedViewController = tVC1;

        [array release];
    [TVC release];
    [TVC release];       
        [detail autorelease];

    }
    return self;
}
// ....
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
{
    if (item == tabBarItem1) {

        CustomTableViewController1 *tVC1 = [detailViews objectAtIndex:0];
        [self.selectedViewController.view removeFromSuperview];
        [self.view addSubview:tVC1.view];
        self.selectedViewController = tVC1;

    } else if (item == tabBarItem2) {
        CustomTableViewController2 *tVC2 = [detailViews objectAtIndex:1];
        [self.selectedViewController.view removeFromSuperview];
        [self.view addSubview:tVC2.view];
        self.selectedViewController = tVC2;
    }
}
@end

自定义表格视图控制器位于标签栏内部,具有一些默认值,需要由用户更改并保存。我可以在我的TabViewController类的uinavigationbar上添加一个右键,但它不能在标签栏中丰富CustomTableViewController中的信息。有没有办法在自定义表视图控制器上添加uinavigationbar上的右键?你能告诉我解决方案吗?

0 个答案:

没有答案