2012-10-30 40 views
0

在界面生成器中,我的標籤欄出現,但它不會顯示在我的模擬器中。我試着重新定位它,並在界面構建器中搞亂了它,但它仍然沒有顯示出來。爲什麼是這樣? 這裏是編碼標籤欄沒有出現在模擬器中

#進口 #進口

@interface MapView類:{的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 

回答

0

我不知道你的MapView被遮蓋在標籤欄,因爲要初始化用的MapView與您的整個視圖(self.view.bounds)相同的框架。

如果是這樣的問題,請嘗試的

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」。

+0

完美的工作謝謝你。查找用戶的位置現在不工作,但?有關於此的任何提示? –

+0

很高興工作。請點擊'檢查'接受答案。 – Hap