我不知道如何停止 IBAction。我需要什么:我按下按钮,然后调用运行大约 5 分钟的 IBAction。我想让取消按钮在按下时从第一个按钮停止 IBAction。
我该怎么做呢?
代码:
- (IBAction)download:(id)sender {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^ {
// Determile cache file path
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
for (i=0;i<=7;i++) {
//Updating progressView and progressLabel
dispatch_async(dispatch_get_main_queue(), ^ {
progressSlider.progress = (float)i/(float)299;
progressLabel.text = [NSString stringWithFormat:@"Загружено: %d из 299",i];
});
NSString *filePath = [NSString stringWithFormat:@"%@/avto-0-%d.html", [paths objectAtIndex:0],i];
// Download and write to file
NSString *mustUrl = [NSString stringWithFormat:@"http://www.mosgortrans.org/pass3/shedule.php?type=avto&%@", [listOfAvtoUrl objectAtIndex:i]];
NSURL *url = [NSURL URLWithString:mustUrl];
NSData *urlData = [NSData dataWithContentsOfURL:url];
[urlData writeToFile:filePath atomically:YES];
}
});
}