I have a view1 and view2. In view1 i have set a dynamically tab-bar with two tab-bar items. Now i want to set on view1, that is in which i have add tab bar, at first tab bar item. And on second tab-bar item i want to set view2. Now tell me how set view1 on first tab bar item so that when user click on tab bar item1 then display view1 again with same data? How do that? i use this code for tab bar
- (void)viewDidLoad {
self.title = @"Business Details";
CGRect myTab =CGRectMake(0,368,320,49);
UITabBar *tabBar = [[[UITabBar alloc] initWithFrame:myTab] autorelease];
NSMutableArray *items = [[[NSMutableArray alloc] init] autorelease];
// Add a 'contacts' item
[items addObject:[[[UITabBarItem alloc] initWithTitle:@"Detail View" image:nil tag:1] autorelease] ];
// Add a 'More' item
[items addObject:[[[UITabBarItem alloc] initWithTitle:@"Review" image:nil tag:2] autorelease] ];
// Put the items in the tab bar
tabBar.items = items;
// Setup this object to respond to tab changes
tabBar.delegate = self;
[self.view addSubview:tabBar];
[super viewDidLoad];
}
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
switch (item.tag ) {
case 1:
dv=[[[DetailView alloc]initWithNibName:@"DetailView" bundle:nil]autorelease];
[self.navigationController pushViewController:dv animated:YES];
self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil] autorelease];
break;
case 2:
review_view=[[[Review alloc]initWithNibName:@"Review" bundle:nil]autorelease];
[self.navigationController pushViewController:review_view animated:YES];
self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:nil action:nil] autorelease];
default:
break;
}
}
Thanks in advance...
I guess you can just create a new project using the Tabbar application template, thats way easier than implementing it yourself and works perfectly.
If you want the tabbar inside of a subview or modal view, or just not in the main view then thats almost easier. In the view were you want the tabbar drag and drop a tabbar controller into the xib. Set your views for the individual tabs (still in IB) and to let the tabbarcontroller appear, simply create an IBOutlet and connect it to your tabbarcontroller and add it as superview when you want it to appear: [self.view addSubview:tabbarController]