我在一个类的第一个方法里给属性赋值,如果出了方法,在另外一个方法调用属性,属性值为空。
但如果我在第一个方法里最后直接调用另一个方法,属性值又正常,请问什么原因导致的?
以下代码:
#import "TSNPopView.h"
typedef void(^completion)();
static completion disCom = ^{};
@interface TSNPopView ()
@property (assign,nonatomic) CGPoint disPoint ;
@end
@implementation TSNPopView
- (IBAction)closeView:(UIButton *)sender {
NSLog(@"%lf", self.disPoint.x);//这里调用的属性的值在自己手动调用时会为空
[self disappearToPoint: self.disPoint completion:^{
disCom();
}];
}
-(void)disappearToPoint:(CGPoint)point completion:(void(^)())completion {
[UIView animateWithDuration:0.5 animations:^{
self.center = point;
self.transform = CGAffineTransformMakeScale(0.01, 0.01);
} completion:^(BOOL finished) {
[self removeFromSuperview];
completion();
}];
}
-(void)showToPoint:(CGPoint)showPoint disappearToPoint:(CGPoint)disPoint completion:(void(^)())completion{
TSNPopView * popView = [[NSBundle mainBundle] loadNibNamed:@"TSNPopView" owner:nil options:nil][0];
popView.center =showPoint;
[[UIApplication sharedApplication].keyWindow addSubview:popView];
self.disPoint = disPoint; //给属性赋值
disCom = completion;
//UIButton * btn= [[UIButton alloc] init];
//[self closeView:btn];//这里主动调用方法 属性就会赋值正常。
}
@end
截图:
上面是主动调用的,下面是手动点击按钮调用的
Mula-mula pastikan sama ada kaedah dengan
self.disPoint = disPoint;
dilaksanakan dahulu, dan kemudiancloseView:
.Jika itu masih tidak berkesan, tambahkan KVO dan lihat apabila nilai berubah.