我正在尝试创建一个应用程序,类似于 Apple 的 BirdSighting 示例(“您的第二个 iOS 应用程序”)。我使用的是主题而不是鸟类,每个主题都有一个标题 ( title
)、一些核心主题 ( core
) 和一些案例研究 ( datacase
)。当我尝试在我的数据控制器 ( SubjectController.m
) 中初始化一个主题时,我在以subject = [[Subject alloc]....
. 任何想法 - 也许与使用数组有关?
subject.h 文件:
#import <Foundation/Foundation.h>
@interface Subject : NSObject
@property (nonatomic, copy) NSString *title;
@property (nonatomic, strong) NSArray *core;
@property (nonatomic, strong) NSArray *datacase;
-(id)initWithTitle:(NSString *)title core:(NSArray *)core datacase:(NSArray *)datacase;
@end
主题.m 文件:
#import "Subject.h"
@implementation Subject
-(id)initWithTitle:(NSString *)title core:(NSArray *)core datacase:(NSArray *)datacase
{
self = [super init];
if (self) {
_title = title;
_core = core;
_datacase = datacase;
return self;
}
return nil;
}
@end
主题控制器.h:
#import <Foundation/Foundation.h>
@class Subject;
@interface SubjectController : NSObject
@property (nonatomic, copy) NSMutableArray *masterSubjectList;
-(NSUInteger)countOfList;
-(Subject *)objectInListAtIndex:(NSInteger)theIndex;
-(void)addSubjectWithSubject:(Subject *)subject;
@end
主题控制器.m:
#import "SubjectController.h"
#import "Subject.h"
@interface SubjectController ()
-(void)createSubjectList;
@end
@implementation SubjectController
-(id) init {
if (self = [super init]) {
[self createSubjectList];
return self;
}
return nil;
}
-(void)createSubjectList {
NSMutableArray *subjectList = [[NSMutableArray alloc] init];
self.masterSubjectList = subjectList;
Subject *subject;
subject = [[Subject alloc] initWithTitle:@"Maths" core:@"Introduction", @"Adding", @"Subtracting" datacase:@"Case 1", @"Case 2", @"Case 3", nil];
[self addSubjectWithSubject:subject];
}
-(void)setMasterSubjectList:(NSMutableArray *)newList {
if (_masterSubjectList != newList) {
_masterSubjectList = [newList mutableCopy];
}
}
-(NSUInteger)countOfList {
return [self.masterSubjectList count];
}
-(Subject *)objectInListAtIndex:(NSInteger)theIndex {
return [self.masterSubjectList objectAtIndex:theIndex];
}
-(void)addSubjectWithSubject:(Subject *)subject {
[self.masterSubjectList addObject:subject];
}
@end