2013-09-23 38 views
1

這是我的筆尖文件和地圖視圖的屏幕,但地圖總是採取整個view.I嘗試重置我的模擬器和清理我的Xcode,但沒有任何作品。我在做有問題? 我是否需要以編程方式爲mapview提供框架?mkmapview根據nib文件中的幀不顯示

http://prntscr.com/1sy1bw

我還希望按鈕是對MapView類的頂部如果地圖不能設置取特定幀。

考慮下面的代碼,請:

#import "mapViewController.h" 

@interface mapViewController() 

@end 

@implementation mapViewController 
@synthesize mapView,source,dest,latdest,latsource,longdest,longsource; 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
{ 
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
if (self) 
{ 
    [email protected]"delhi"; 
} 
return self; 
} 

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0,0,160,240)]; 
CLGeocoder *geocoder1 = [[CLGeocoder alloc] init]; 
[geocoder1 geocodeAddressString:source 
      completionHandler:^(NSArray* placemarks, NSError* error) 
{ 
    for (CLPlacemark* aPlacemark in placemarks) 
    { 
     coordinate.latitude = aPlacemark.location.coordinate.latitude; 
     latsource=&coordinate.latitude; 
     coordinate.longitude = aPlacemark.location.coordinate.longitude; 
     longsource=&coordinate.longitude; 
     MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init]; 
     [annotation setCoordinate:(coordinate)]; 
     [annotation setTitle:source]; 
     annotation.subtitle = @"I'm here!!!"; 
     mapView.delegate = self; 
     [self.mapView addAnnotation:annotation]; 

    } 
}]; 
} 
+0

你試過以編程方式設置框架嗎? – NightFury

+0

還沒有,但我試過嗎? –

+0

顯然。有時它發生,我們不能從nib文件管理代碼,然後我們嘗試以編程方式執行它 – NightFury

回答

1
- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
//mapView = [[MKMapView alloc] initWithFrame:CGRectMake(0,0,160,240)]; 
CLGeocoder *geocoder1 = [[CLGeocoder alloc] init]; 
[geocoder1 geocodeAddressString:source 
      completionHandler:^(NSArray* placemarks, NSError* error) 
    { 
    for (CLPlacemark* aPlacemark in placemarks) 
     { 
     coordinate.latitude = aPlacemark.location.coordinate.latitude; 
     latsource=&coordinate.latitude; 
     coordinate.longitude = aPlacemark.location.coordinate.longitude; 
     longsource=&coordinate.longitude; 
     MKPointAnnotation *annotation = [[MKPointAnnotation alloc] init]; 
     [annotation setCoordinate:(coordinate)]; 
     [annotation setTitle:source]; 
     annotation.subtitle = @"I'm here!!!"; 
     [self.view addSubview:mapView]; 
     [self.mapView addAnnotation:annotation]; 
     } 
    }]; 
} 

我評論的MapView ALLOC代碼行和這個固定喜歡的MapView的issue.Seems得到儘快推動其分配的內存space.Moreover框架協調,使得我初始化mapviewview仍然保留,雖然代碼評論。不知道它是否應該只用這種方式,但它確實解決了我的問題。