主要代码在 B ViewController 里面.
@interface BViewController ()
@property (strong, nonatomic) NSMutableArray *tmpData;
@end
@implementation BViewController
- (void)dealloc
{
NSLog(@"---------------------------");
NSLog(@"MyViewController dealloc.");
NSLog(@"---------------------------");
}
- (void)viewDidLoad
{
[super viewDidLoad];
_tmpData = [NSMutableArray arrayWithObjects:@"mark.z", nil];
UIButton *cloneMeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[cloneMeBtn setTitle:@"close" forState:UIControlStateNormal];
cloneMeBtn.backgroundColor = [UIColor blueColor];
cloneMeBtn.frame = CGRectMake(130, 300, 80, 50);
[self.view addSubview:cloneMeBtn];
[cloneMeBtn addTarget:self action:@selector(close) forControlEvents:UIControlEventTouchUpInside];
[self performSelector:@selector(block1) withObject:nil afterDelay:3.0f];
}
- (void)block1
{
[UIView animateWithDuration:1 animations:^{
NSLog(@"tmpArray = %@", self.tmpData);
[self.tmpData addObject:@"hk"];
NSMutableArray *array = self.tmpData;
[array addObject:@"ju"];
} completion:^(BOOL finished) {
}];
}
- (void)block2:(id)sender
{
NSLog(@"sender = %@", sender);
MyViewController __weak *weakSelf = sender;
[UIView animateWithDuration:1 animations:^{
NSLog(@"tmpArray = %@", weakSelf.tmpData);
[weakSelf.tmpData addObject:@"hk"];
NSMutableArray *array = weakSelf.tmpData;
[array addObject:@"ju"];
} completion:^(BOOL finished) {
}];
}
- (void)block3
{
[UIView animateWithDuration:1 animations:^{
NSLog(@"tmpArray = %@", _tmpData);
[_tmpData addObject:@"hk"];
NSMutableArray *array = _tmpData;
[array addObject:@"ju"];
NSLog(@"tmpArray = %@", _tmpData);
} completion:^(BOOL finished) {
}];
}
- (void)close
{
[self dismissViewControllerAnimated:YES completion:^{
}];
}
@end
tmpArray = (
"mark.z"
)
---------------------------
MyViewController dealloc.
---------------------------
sender = (null)
tmpArray = (null)
---------------------------
MyViewController dealloc.
---------------------------
看来不是, self 的问题.
tmpArray = (
"mark.z"
)
tmpArray = (
"mark.z",
hk,
ju
)
---------------------------
MyViewController dealloc.
---------------------------
+ (void)cancelPreviousPerformRequestsWithTarget:(id)aTarget selector:(SEL)aSelector object:(nullable id)anArgument;
+ (void)cancelPreviousPerformRequestsWithTarget:(id)aTarget;
- (void)close
{
[NSObject cancelPreviousPerformRequestsWithTarget:self];
[self dismissViewControllerAnimated:YES completion:^{
}];
}