(代码更新)在 IOS 7 更新后,我的应用程序因单例标签而崩溃(这仅在设备中发生)...第一次访问单例一切正常,但第二次 ClassSingleton 为零。任何人都可以帮忙吗?(在 IOS 7 之前一切都很好......现在我得到 Bad Access Code =1)
我正在使用ARC ...
谢谢
类单例.h
@property (nonatomic, strong) IBOutlet UILabel *lblResultado;
类单例.m
@synthesize lblResultado;
__strong static ClassSingleton *pOutClassSingletonReturn = nil;
#pragma mark Singleton Methods
+ (void)initialize
{
pOutClassSingletonReturn = [[super allocWithZone:NULL] init];
pOutClassSingletonReturn.lblResultado = [[UILabel alloc] init];
pOutClassSingletonReturn.lblResultado.backgroundColor = [UIColor clearColor];
pOutClassSingletonReturn.lblResultado.textColor = [UIColor whiteColor];
pOutClassSingletonReturn.lblResultado.textAlignment = NSTextAlignmentRight;
pOutClassSingletonReturn.lblResultado.text = @"0";
}
+ (ClassSingleton*) pOutClassSingletonReturn
{
return pOutClassSingletonReturn;
}
@end
访问类.m
@implementation AccessClass
__strong static ClassSingleton *pOutClassSingletonReturn;
- (void)viewDidLoad
{
[super viewDidLoad];
externalsObjects = [NSDictionary dictionaryWithObject:[ClassSingleton pOutClassSingletonReturn] forKey:@"pOutClassSingletonReturn"];
nibOptions = [NSDictionary dictionaryWithObject:externalsObjects forKey:UINibExternalObjects];
[self.nibBundle loadNibNamed:self.nibName owner:self options:nibOptions];
pOutClassSingletonReturn = [ClassSingleton pOutClassSingletonReturn];
pOutClassSingletonReturn.lblResultado.text = @"1";
}
- (IBAction) button: (id) sender
{
pOutClassSingletonReturn.lblResultado.text = @"blabla"; //==>>> Crash second time i press the button
}