将NSNotificationCenter -addObserver:selector:name:object:
或-removeObserver:name:object:
与UIContentSizeCategoryDidChangeNotification
一起使用时,我在iOS 6上收到EXEC_BAD_ACCESS code=1, address=0x0
。
我在-viewWillAppear:
和-viewWillDisappear:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIContentSizeCategoryDidChangeNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(preferredFontSizeChanged:) name:UIContentSizeCategoryDidChangeNotification object:nil];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIContentSizeCategoryDidChangeNotification object:nil];
}
此外,请注意UIContentSizeCategoryDidChangeNotification
声明为:
UIKIT_EXTERN NSString *const UIContentSizeCategoryDidChangeNotification NS_AVAILABLE_IOS(7_0);
哪个解析为:
#define UIKIT_EXTERN extern __attribute__((visibility ("default")))
答案 0 :(得分:1)
通常,iOS SDK中的常量声明为extern NSString
。 extern
关键字是一个合同,声明此内存将在另一个编译单元中分配。因此,在iOS 6中,该通知类型不存在,因此错误访问是由于未分配字符串。