'birdsighting'没有可见的@interface声明选择器'initwithname:location:date:'

时间:2012-11-24 13:30:33

标签: ios xcode

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

#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

1 个答案:

答案 0 :(得分:0)

检查Birdsighting.h并确保方法

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

在那里宣布。这基本上告诉其他类Bidsighting类的实例可以使用哪些方法。

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