1

我是 ios 编程的新手,并且停留在我的第二个教程中,该教程在 developer.apple.com 中调用了关于观鸟的第二个 iOS 应用程序。在“在细节场景中显示信息”部分的末尾,当我运行代码时,BirdSightingDataController.m 文件中出现“'birdsighting' 没有可见的@interface 声明选择器'initwithname:location:date:'”错误"sighting = [[BirdSighting alloc] initWithName:@"Pigeon" location:@"Everywhere" date:today];" 线。我检查了很多次文档并再次进行了 tut 但找不到如何纠正这个问题?

#import "BirdSightingDataController.h"
#import "BirdSighting.h"
@interface BirdSightingDataController ()
- (void)initializeDefaultDataList;
@end
@implementation BirdSightingDataController
- (void)initializeDefaultDataList {
    NSMutableArray *sightingList = [[NSMutableArray alloc] init];
    self.masterBirdSightingList = sightingList;
    BirdSighting *sighting;
    NSDate *today = [NSDate date];
    sighting = [[BirdSighting alloc] initWithName:@"Pigeon" location:@"Everywhere" date:today];
    [self addBirdSightingWithSighting:sighting];
}
- (void)setMasterBirdSightingList:(NSMutableArray *)newList {
    if (_masterBirdSightingList != newList) {
        _masterBirdSightingList = [newList mutableCopy];
    }
}
- (id)init {
    if (self = [super init]) {
        [self initializeDefaultDataList];
        return self;
    }
    return nil;
}
- (NSUInteger)countOfList {
    return [self.masterBirdSightingList count];
}
- (BirdSighting *)objectInListAtIndex:(NSUInteger)theIndex {
    return [self.masterBirdSightingList objectAtIndex:theIndex];
}
- (void)addBirdSightingWithSighting:(BirdSighting *)sighting {
    [self.masterBirdSightingList addObject:sighting];
}
@end

Birdsighting.h 文件

#import <Foundation/Foundation.h>

@interface BirdSighting : NSObject

@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *location;
@property (nonatomic, strong) NSDate *date;
-(id)initWithName:(NSString *) name locaiton:(NSString *)location date:(NSDate *) date;

@end
4

1 回答 1

0

检查 Birdsighting.h 并确保该方法

- (id)initWithName:(NSString *)name location:(NSString *)location date:(NSDate *)date;

在那里声明。这实质上是告诉其他类哪些方法可用于 Bidsighting 类的实例。

接口声明中可能存在拼写错误(即使在苹果示例中也会发生这种情况)。

于 2012-11-24T13:36:52.373 回答