我有一个带有许多UINavigationController的标签栏的UIViewController。标签栏以编程方式创建。当我点击第一个UITabItem它显示一个UITable时,当我再次点击它时,它显示了地图,所以我可以在它们之间切换。 UITable和MKMapView在同一视图中,我使用sethidden yes或no在它们之间切换。问题是,这不起作用,我发现了原因,但我不知道为什么会发生这种情况 这是隐藏和显示的函数的代码:
-(void) showMap
{
fieldsTableView.hidden = YES;
[mapView setHidden:NO];
}
-(void) showList
{
fieldsTableView.hidden = NO;
mapView.hidden = YES;
}
以下是调用这些方法的代码:
-(void) showFieldsView
{
@try
{
if(self.fieldsViewController == nil)
{
self.fieldsViewController = [[FieldsViewController alloc] initWithNibName:@"FieldsView" bundle:nil];
}
if(currentViewController == nil)
{
[self showFieldsListView];
currentViewController = fieldsNavController;
}
NSString *viewtype = [[NSString alloc] initWithString:[(UITabBarItem *)[self.tabBar.items objectAtIndex:0] title]];
if(currentViewController == self.fieldsNavController)
{
if (viewtype == @"List")
{
[(UITabBarItem *)[self.tabBar.items objectAtIndex:0] setTitle:@"Map"];
[(UITabBarItem *)[self.tabBar.items objectAtIndex:0] setImage:[UIImage imageNamed:@"map.png"]];
[fieldsViewController showMap];
}
else
{
[self.fieldsViewController showList];
[(UITabBarItem *)[self.tabBar.items objectAtIndex:0] setTitle:@"List"];
[(UITabBarItem *)[self.tabBar.items objectAtIndex:0] setImage:[UIImage imageNamed:@"list.png"]];
}
}
else
{
[self showFieldsListView];
currentViewController = self.fieldsNavController;
}
[viewtype release];
}
@catch (NSException *exception) {
NSLog(@"Exception in tabViewControlelr showFieldsView \nDescription %@", [exception description]);
}
}
- (void) showFieldsListView {
[self.fieldsNavController viewWillAppear:YES];
[self.fieldsNavController.view addSubview:tabBar];
[self.view addSubview:self.fieldsNavController.view];
}
我做了一个NSLOG,这是我发现的:当调用showMap或showList函数时,它被调用,内部完成,但是没有访问属性,它显示NULL(我试图显示另一个字符串属性并显示NULL) 这是宣言:
UITableView * fieldsTableView;
MKMapView *mapView;
和
@property (nonatomic, retain) UITableView * fieldsTableView;
@property (nonatomic, retain) MKMapView *mapView;