我收到此错误:
exc_bad_access (code=1, address=0x2012
当我尝试以这种方式从单例接收值时:
Draggable* sharedSingleton = [Draggable sharedManagerDraggable];
NSLog(@"%@", sharedSingleton.namePassedToDraggable);
上面的代码放在UIImageView类型的Draggable.m中,里面也有:
+ (Draggable *)sharedManagerDraggable
{
static Draggable *sharedManagerDraggable = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedManagerDraggable = [[Draggable alloc] init];
});
return sharedManagerDraggable;
}
我以这种方式(来自 view controller.m)为 namePassedToDraggable 赋值:
#import Draggable.h
Draggable* sharedSingleton = [Draggable sharedManagerDraggable];
sharedSingleton.namePassedToDraggable = txt.text;
NSLog(@"%@", sharedSingleton.namePassedToDraggable);
dragger.tag = img.tag;
在 Draggable.h 我有:
+ (Draggable *) sharedManagerDraggable;
@property (nonatomic, assign) NSString* namePassedToDraggable;
为什么我会收到导致应用程序崩溃的错误?我在其他视图控制器中使用相同的方法,效果很好!