NSNotificationCenter
观察者,它会在两个不同的视图控制器上调用具有相同名称的2个选择器。它可以工作,但当我运行应用程序时,有时会崩溃,并显示以下错误消息:
Thread 1: EXC_BAD_ACCESS (code=1, address=0x18)
或者
Thread 1: EXC_BAD_ACCESS (code=EXC_I386_GPFLT)
有人知道为什么它会崩溃吗?谢谢!
.
我的代码:
fetchFromParse:
-(void)sendAllStores
{
[[NSNotificationCenter defaultCenter]postNotificationName:@"getStoresArrays" object:nil userInfo:self.storesDict];
}
firstVC.m:
- (void)viewDidLoad {
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(getStoresArrays:) name:@"getStoresArrays" object:nil];
}
-(void)getStoresArrays:(NSNotification*)notification
{
NSLog(@“Working”);
}
secondVC.m:
-(void)prepareArrays
{
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(getStoresArrays:) name:@"getStoresArrays" object:nil];
}
-(void)getStoresArrays:(NSNotification*)notification
{
NSLog(@“Working”);
}
AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.secVC=[[secondVC alloc] init];
[self.secVC prepareArrays];
fetchFromParse *fetchFromParseObj=[[fetchFromParse alloc] init];
[fetchFromParseObj getStoresFromParse];
Return YES;
}
self.storesDict
作为通知的用户信息之前,您是否检查过它不是空的?self.secVC
在应用程序委托中是否声明为strong
属性? - John Rogersself.storesDict
不是 nil。而且,secVC
和firstVC
都是强引用属性。 - FS.O