Xcode 选项卡栏未显示在模拟器中

Xcode 选项卡栏未显示在模拟器中,xcode,mapkit,tabbar,Xcode,Mapkit,Tabbar,在interface builder中,我的选项卡栏会显示,但它不会显示在我的模拟器中。我试着重新定位它,在interface builder中摆弄它,但它仍然没有出现。为什么会这样? 这是代码 #进口 #进口 @接口映射视图:UIViewController{ MKMapView *mapView; } -(IBAction)setMap:(id)sender; -(IBAction)pushBack; -(IBAction)findmyass:(id)sender;

在interface builder中,我的选项卡栏会显示,但它不会显示在我的模拟器中。我试着重新定位它,在interface builder中摆弄它,但它仍然没有出现。为什么会这样? 这是代码

#进口 #进口

@接口映射视图:UIViewController{

 MKMapView *mapView; 


}


-(IBAction)setMap:(id)sender;

-(IBAction)pushBack;

-(IBAction)findmyass:(id)sender;








@end

#import "mapview.h"
#import "NewClass.h"


@implementation mapview




-(void)viewDidLoad {
[super viewDidLoad];

mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];  
mapView.delegate=self;  

[self.view addSubview:mapView];  
[NSThread detachNewThreadSelector:@selector(displayMap) toTarget:self withObject:nil];  



[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];

MKCoordinateRegion region = { {0.0, 0.0 }, {0.0, 0.0 } };
region.center.latitude = 39.956907;
region.center.longitude = -75.610229;
region.span.longitudeDelta = 0.01f;
region.span.latitudeDelta = 0.01f;
[mapView setRegion:region animated:YES];


NewClass *ann = [[NewClass alloc] init];
ann.title = @"Vigil Location of Chester County ";
ann.subtitle = @"8 S. Wayne St. West Chester, PA 19382";
ann.coordinate = region.center;
[mapView addAnnotation:ann];

-(void)displayMap {  
MKCoordinateRegion region;  
MKCoordinateSpan span;  
span.latitudeDelta=0.2;  
span.longitudeDelta=0.2;  

CLLocationCoordinate2D location;  
location.latitude = -35;  
location.longitude = 146.2381;  
region.span=span;  
region.center=location;  

[mapView setRegion:region animated:TRUE];  
[mapView regionThatFits:region];  
}  

- (void)dealloc {  
[mapView release];  
[super dealloc];  
}  




/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a        
- (void)viewDidLoad {
[super viewDidLoad];
}
*/

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:    (UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
 }

 - (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
 }






-(IBAction)pushBack {

[self dismissModalViewControllerAnimated:YES];
 }

 -(IBAction)findmyass:(id)sender {

mapView.showsUserLocation = YES;

 } 

 @end

我想知道您的mapView是否覆盖了选项卡栏,因为您正在使用与整个视图相同的框架(self.view.bounds)初始化mapView

如果这是问题所在,试试看

CGRect frame = self.view.bounds;
frame.size.height = frame.size.height - 40;
mapView = [[MKMapView alloc] initWithFrame:frame]; 
而不是

mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];  

这应该会告诉你这是否是你的问题。如果是这样,你可能应该得到一个对选项卡栏的引用并减去它的高度,而不是硬编码的“40”。

这非常有效。谢谢你。但是现在找用户位置不起作用了?有什么提示吗?很高兴这起到了作用。请单击“检查”接受答案。