我已經創建了一個tabbar通過筆尖與基於視圖的應用程序中的三個項目。
我希望在出現視圖時默認選擇第一項。在基於視圖的應用程序中的Tabbar項不起作用
問題是item1顯示選中,但它沒有加載它有權做的視圖。當我們點擊該項目時,視圖出現。請幫我解決這個問題。這裏是我的代碼...
-(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
}
}
他似乎使用'UITabBar',而不是一個'UITabBarController'。 – 2012-02-06 04:26:24