ClassA.h東西EXC_BAD_ACCESS上一座座 「回調」
typedef void (^ ValidatorBlock)(BOOL);
...
@interface ClassA : NSObject {
ValidatorBlock validatorBlock;
}
...
- (void)setValidatorBlock:(ValidatorBlock)block;
...
@property (nonatomic, retain) ValidatorBlock validatorBlock;
ClassA-> setValidatorBlock
- (void)setValidatorBlock:(ValidatorBlock)block {
validatorBlock = [block copy];
}
ClassA-> validateForm
- (void)validateForm {
validatorBlock(NO);
}
ClassA-> textFieldDidEndEditing
- (void)textFieldDidEndEditing:(UITextField *)textField {
[self validateForm];
}
ClassB-> viewDidLoad中 - 其中魔術發生
void (^block)(BOOL) = ^(BOOL is_valid) {
// works fine when passed NO, always crashes when passed YES with EXC_BAD_ACCESS
NSLog(@"block: %@", is_valid);
};
ClassA *classA = [[ClassA alloc] init];
[classA setValidatorBlock:block];
我撇去了一些谷歌的文章我與copy
實現仍然給了我同樣的問題。有任何想法嗎?
** 答案 **
@vikingosegundo共享上String Specifier Formats
+1添加有用的信息,爲未來的讀者 – vikingosegundo