【发布时间】:2014-05-14 02:12:41
【问题描述】:
我有两个自定义类:FSGame 和 FSEvent。 FSGame 有一个 ivar,它应该是 NSMutableArray 的 FSEvent 对象。
这是 FSGame.h:
@interface FSGame : NSObject
@property (strong, nonatomic) NSMutableArray *players;
@property (strong, nonatomic) NSString *startTime;
@property (strong, nonatomic) NSString *endTime;
@property (strong, nonatomic) NSMutableArray *gameEvents;
@end
这是我的 FSEvent.h:
@interface FSEvent : NSObject
@property NSInteger ID;
@property NSInteger pointTo;
@end
我用
@property (strong, nonatomic) FSGame *game;
在我的AppDelegate 中保留FSGame 的实例。然后,在我的application:didFinishLaunchingWithOptions: 中创建FSGame 的一个实例,以便在整个“游戏”中填充它。
_game = [[FSGame alloc] init];
然后,在我的一个视图控制器中,我 alloc 和 init 是 FSEvent 的一个实例,然后尝试将其添加到 .gameEvents 数组中:
[appDelegate.game.gameEvents addObject: event];
但这里似乎出了点问题,因为如果我尝试从另一个视图控制器访问该对象,它将是 nil:
FSEvent *previousEvent = [appDelegate.game.gameEvents lastObject];
if (previousEvent == nil) {
NSLog(@"previousEvent is NIL!");
}
我在这里错过了什么?
【问题讨论】:
-
你检查过
appDelegate.game.gameEvents不是nil吗?
标签: ios objective-c class instance-variables appdelegate