我提出customViewController
并试图通过委托解雇自己。它只适用于第一次。当我再次presentCustomViewController
时,会出现view controller
,但它无法解散。但是,当我尝试通过按钮解除它时,它每次都有效。你能告诉我原因是什么吗?
- (void)presentCustomViewController {
CustomViewController *customViewController = [self.window.rootViewController.storyboard instantiateViewControllerWithIdentifier:@"CustomViewController"];
customViewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
customViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
customViewController.delegate = self;
[self.window.rootViewController presentViewController:customViewController animated:YES completion:nil];
}
#pragma mark - CustomViewController
@implementation CustomViewController {
NSURLSession *backgroundSession;
NSURLSessionDownloadTask *downloadTask;
}
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
backgroundSession = nil;
self.mailComposeViewController = nil;
self.documentInteractionController = nil;
[self startDownload];
}
- (void)startDownload {
NSURLSessionConfiguration *backgroundConfigurationObject = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:@"myBackgroundSessionIdentifier"];
backgroundSession = [NSURLSession sessionWithConfiguration:backgroundConfigurationObject delegate:self delegateQueue:[NSOperationQueue mainQueue]];
downloadTask = [backgroundSession downloadTaskWithURL:[NSURL URLWithString:_attachment.url]];
[downloadTask resume];
}
- (IBAction)cancelButtonClicked:(id)sender {
[downloadTask cancel];
self.mailComposeViewController = nil;
self.documentInteractionController = nil;
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - CustomViewControllerDelegate
- (void)viewController:(CustomViewController *)viewController {
[viewController dismissViewControllerAnimated:YES completion:nil];
NSLog(@"%@, %d", viewController, [viewController isBeingDismissed]);
}
日志:
<CustomViewController: 0x100691390>, 1
<CustomViewController: 0x100691390>, 0