Model-View-Controller approach suggests that the boolean value belongs in the Model code of your application. It is a common thing to make your model a singleton:
QuizModel.h
@interface QuizModel : NSObject
@property (nonatomic, readwrite) BOOL isMultiplayer;
-(id)init;
+(QuizModel*)instance;
@end
QuizModel.m
static QuizModel* inst = nil;
@implementation QuizModel
@synthesize isMultiplayer;
-(id)init {
if(self=[super init]) {
self.isMultiplayer = NO;
}
return self;
}
+(QuizModel*)instance {
if (!inst) inst = [[QuizModel alloc] init];
return inst;
}
@end
Now you can use the boolean in your controller code: include "QuizModel.h"
, and write
if ([QuizModel instance].isMultiplayer)
or
[QuizModel instance].isMultiplayer = YES;
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…