I have a problem when add a right button on uinavigationbar. My Nib organizer like this:
CustomTabViewController :UIViewController
-->CustomTableViewController1 : UIViewController
-->CustomTableViewController2 : UIViewController
CustomTabViewControllers are in Tabbar items
I need to save the inputs, I can add navigation item from Navigation Controller, but I can't add them from View Controller when they are childs in Tabbar items. here is my code:
@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
the Custom Table View Controllers are inside the tab bars with some default value which need to be change by user and save. I can add a right button on uinavigationbar from my TabViewController class but it can not rich the information inside CustomTableViewController in tab bars. Is there any way to add a right button on uinavigationbar from Custom Table View Controller which I have? Can you show me the solution?