我看到了来自 iOS 开发人员的一些代码。它有一些代码如下:
void (^block)(NSUInteger buttonIndex, UIAlertView *alertView) = objc_getAssociatedObject(self, "blockCallback");
但。我不明白为什么将对象 self 分配给块代码。该方法的完整代码为:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
void (^block)(NSUInteger buttonIndex, UIAlertView *alertView) = objc_getAssociatedObject(self, "blockCallback");
if (block) {
block(buttonIndex, self);
}
}