我是 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