2010-11-12 38 views
5

嘿所有, 我试图让MKMapView启动并运行,但我似乎无法通过似乎是一个参考错误。我已经花了几个小时用google搜索了这个以及昨晚。MKMapKit和IOS4

页眉:

#import <UIKit/UIKit.h> 
#import <MapKit/MapKit.h> 

@interface MapsViewController : UIViewController { 
    MKMapView *mapView; 
} 

@end 

主营:

#import "MapsViewController.h" 

@implementation MapsViewController 
- (void)viewDidLoad { 
    [super viewDidLoad]; 
    mapView = [[MKMapView alloc] initWithFrame:self.view.frame]; 
    [self.view insertSubview:mapView atIndex:0]; 
} 

- (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; 
} 
- (void)dealloc { 
    [super dealloc]; 
    [mapView dealloc]; 
} 

@end 

错误:

Build Maps of project Maps with configuration Debug 

Ld build/Debug-iphonesimulator/Maps.app/Maps normal i386 
cd /workspace/iphone_dev/Maps 
setenv MACOSX_DEPLOYMENT_TARGET 10.6 
setenv PATH "/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin" 
/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc-4.2 -arch i386 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.1.sdk -L/workspace/iphone_dev/Maps/build/Debug-iphonesimulator -F/workspace/iphone_dev/Maps/build/Debug-iphonesimulator -filelist /workspace/iphone_dev/Maps/build/Maps.build/Debug-iphonesimulator/Maps.build/Objects-normal/i386/Maps.LinkFileList -mmacosx-version-min=10.6 -Xlinker -objc_abi_version -Xlinker 2 -framework Foundation -framework UIKit -framework CoreGraphics -o /workspace/iphone_dev/Maps/build/Debug-iphonesimulator/Maps.app/Maps 

Undefined symbols: 
    "_OBJC_CLASS_$_MKMapView", referenced from: 
     objc-class-ref-to-MKMapView in MapsViewController.o 
ld: symbol(s) not found 
collect2: ld returned 1 exit status 

我设法找到MKMapKit.framework相应的文件夹。他们是我缺少的东西吗?

回答

10

听起来像你需要添加MapKit.framework到你的项目,方法是右键单击Xco​​de中的项目列表并选择Add-> Existing Framework。选择MapKit,你会看到它列在目标 - >你的应用程序 - >链接二进制库。

+0

你知道可悲的事情是?我想我昨天晚上在另一个线下喝了几杯啤酒后,就读到了这个答案。哈哈感谢队友。我知道我错过了一些简单的事情! – jbcurtin 2010-11-12 19:46:54

+0

谢谢bosmacs! – 2011-03-14 02:47:47

3

bosmacs说的是正确的。还要注意你的dealloc方法是不正确的。

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

你绝对不应该在除super以外的任何东西上调用dealloc,[super dealloc];总是在你的dealloc方法结束时进行。