MKMapKit 和 IOS4
嘿大家, 我正在尝试让 MKMapView 启动并运行,但是我似乎无法克服似乎是参考错误的问题。我花了几个小时在谷歌上搜索这个以及昨晚。
标题:
#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。他们是我缺少的东西吗?
Hey all,
I'm trying to get the MKMapView up and running however I can't seem to get past what seems to be a reference error. I've spent a few hours googling this as well as last night.
Header:
#import <UIKit/UIKit.h>
#import <MapKit/MapKit.h>
@interface MapsViewController : UIViewController {
MKMapView *mapView;
}
@end
Main:
#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
Error:
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
I managed to find the MKMapKit.framework in the appropriate folders. Is they anything I'm missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来您需要通过右键单击 Xcode 中的项目列表并选择“添加”->“现有框架”来将 MapKit.framework 添加到您的项目中。选择 MapKit,您应该会看到它列在 Targets -> 下您的应用程序 ->将二进制文件与库链接。
Sounds like you need to add MapKit.framework to your project by right-clicking on your project list in Xcode and choosing Add->Existing Framework. Choose MapKit, and you should see it listed under Targets -> Your App -> Link Binary with Libraries.
博斯马克说的是正确的。另请注意,您的 dealloc 方法不正确。
除了 super 和 [super dealloc] 之外,你不应该对任何东西调用 dealloc;总是出现在 dealloc 方法的末尾。
What bosmacs said is correct. Also note that your dealloc method is incorrect.
You should NEVER call dealloc on anything but super, and [super dealloc]; always goes at the end of your dealloc method.