我有TableViewController和ViewController。我想在下载音频后进入ViewController。但我是在音频下载的时候去的。我使用fileExists,它检查音频是否被下载。但不起作用。在ViewController下载音频之后,我怎么进去呢?
这是我的下载代码
if (!fileExists) {
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Download audio?" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction* actionAdd = [UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinner.frame = CGRectMake(0, 0, 24, 24);
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryView = spinner;
[spinner startAnimating];
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSString *stringURL = @"https://drive.google.com/uc?export=download&id=0B6zMam2kAK39R2Z5RlVWZkN3Vzg";
NSURL *url = [NSURL URLWithString:stringURL];
NSData *urlData = [NSData dataWithContentsOfURL:url];
[urlData writeToFile:filePath atomically:YES];
});
if (fileExists) {
[self performSegueWithIdentifier: @"detailSegue" sender: self];
}
}];
UIAlertAction* actionCancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}];
[alert addAction:actionAdd];
[alert addAction :actionCancel];
[self presentViewController:alert animated:YES completion:nil];
}
if (fileExists) {
[self performSegueWithIdentifier: @"detailSegue" sender: self];
}
}发布于 2016-04-02 14:00:21
// **在检查器**中设置ViewController标识符之前,尝试使用此方法
ViewController *vc17 = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
[self presentViewController:vc17 animated:YES completion:nil];发布于 2016-04-02 12:08:59
您应该始终在主队列中执行与UI相关的代码,如:
[self performSegueWithIdentifier: @"detailSegue" sender: self];你最好用NSURLSessionDataTask从网上下载一些东西。
https://stackoverflow.com/questions/36372769
复制相似问题