【问题标题】:What's causing this error in a subclass of MKAnnotationView?在 MKAnnotationView 的子类中导致此错误的原因是什么?
【发布时间】:2009-11-19 22:05:17
【问题描述】:

我正在尝试为 iPhone Mapkit 应用程序创建 MKAnnotationView 的子类,但由于某种原因我突然遇到此错误:

Command /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc-4.2 failed with exit code 1

这些是似乎导致错误的代码的头文件和主文件。尽管此文件没有特别显示该错误,但如果我将.m 文件从@implementation 注释到@end,则不会出现该错误。但是,如果我评论实现中的所有内容(不包括 @implementation 本身),它仍然会出现。

PhotoAnnotationView.h

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

@interface PhotoAnnotationView : MKAnnotationView { 
    UIImageView *thumb; 
}

@property (nonatomic, retain) IBOutlet UIImageView *thumb;

@end

PhotoAnnotationView.m

#import "PhotoAnnotationView.h"


@implementation PhotoAnnotationView

@synthesize thumb;

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        // Initialization code
    }
    return self;
}


- (void)drawRect:(CGRect)rect {
    // Drawing code
}


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


@end

这与 Xcode 通过 New File... &gt; Objective-C Class &gt; Subclass of: UIView 创建的代码基本相同,但子类已更改。

我在 Snow Leopard 上运行 Xcode 3.2.1 版。

【问题讨论】:

  • 我应该尝试重新安装 Xcode 吗?我看不出我应该收到此错误的任何充分理由。

标签: iphone xcode compiler-errors mapkit


【解决方案1】:

您是否将您的应用程序与 MapKit.framework 链接?编译器可能不知道 MKAnnotationView cs,因此输出此错误。

要将框架添加到您的项目,请转到 Xcode 菜单之一中的 Target settings(不幸的是,我手头没有 Xcode),然后在第一个选项卡上单击加号按钮并从列表。

我希望这会有所帮助。

【讨论】:

  • 我的项目引用了 CFNetwork、CoreLocation、MapKit、UIKit、Foundation 和 CoreGraphics。而且我之前已经能够使用 MapKit 的功能了。
猜你喜欢
  • 1970-01-01
  • 2011-09-29
  • 2023-04-01
  • 2010-12-16
  • 1970-01-01
  • 2012-07-01
  • 1970-01-01
  • 2012-07-05
  • 1970-01-01
相关资源
最近更新 更多