I have created a tabbar through nib with three items in a view based application.
I want first item get selected by default when the view appear.
The problem is item1 show selected but it doesnt load the view it is entitled to do. when we click on the item the view appears. Please help me to sort out this. here Is my code…
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
tabBar.delegate = self;
[tabBar setSelectedItem:[tabBar.items objectAtIndex:0]];
}
- (void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item {
NSLog(@"didSelectItem: %d", item.tag);
if (item.tag==1) {
ImagesOverlay=[[UIView alloc]initWithFrame:CGRectMake(0, 210, 320, 250)];
ImagesOverlay.backgroundColor=[UIColor grayColor];
[self.view addSubview:ImagesOverlay];
}else if (item.tag==2) {
relatedOverlay=[[UIView alloc]initWithFrame:CGRectMake(0, 210, 320, 250)];
relatedOverlay.backgroundColor=[UIColor redColor];
[self.view addSubview:relatedOverlay];
}else if(item.tag==3){
//other condition
}
}
Just got it done..