iOS:按下按钮时退出方法

时间:2014-10-14 13:21:23

标签: ios objective-c

我想在按下按钮时退出方法。

该方法的调用是通过一个大调度队列。我用while循环尝试了它,但它不起作用。

dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul), ^{
    [self LoadEverything];
    dispatch_async(dispatch_get_main_queue(), ^{
        //other stuff
    });
});

该方法包含不同的下载图像执行。

-(void)LoadEverything{
int currentCount;

// DOWNLOAD PLACE THUMBS
{
    int placesCount = 0;
    NSArray *fullPlacesThumb = [NSArray arrayWithArray:[places valueForKeyPath:@"thumbnail"]];
    for(NSArray *places in fullPlacesThumb)
        placesCount += places.count;

    currentCount = 1;
    self.progressView.progress = 0.0f;

    for(int i=0;i<places.count;i++)
    {
        bool downloadImage = true;

        NSMutableArray *placesThumb = [[NSMutableArray alloc] init];
        NSMutableArray *placesTitle = [[NSMutableArray alloc] init];
        NSString *placeCategoryPath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"category_%d",i]];
        if(![[NSFileManager defaultManager] fileExistsAtPath:placeCategoryPath])
            [[NSFileManager defaultManager]createDirectoryAtPath:placeCategoryPath withIntermediateDirectories:NO attributes:nil error:nil];

        [placesThumb addObjectsFromArray:[places[i] valueForKeyPath:@"thumbnail"]];
        [placesTitle addObjectsFromArray:[places[i] valueForKeyPath:@"title"]];
        NSArray *localFiles = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:placeCategoryPath error:NULL];
        if( [[NSFileManager defaultManager] fileExistsAtPath:placeCategoryPath] && localFiles.count != placesThumb.count)
        {
            for(int j=0;j<placesThumb.count;j++)
            {

                dispatch_async(dispatch_get_main_queue(), ^{
                    [self.info setText:[NSString stringWithFormat:NSLocalizedString(@"splash.loadLocThumbImages", "Loc Thumb Images"),currentCount,placesCount]];
                    self.progressView.progress = ((100.0/placesCount)*currentCount)/100;
                });
                if(placesThumb[j] !=  [NSNull null])
                {
                    NSString *imageURL = [placesThumb[j] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
                    NSData *imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:imageURL]];
                    UIImage *theImage = [[UIImage alloc] initWithData:imageData];
                    NSData *image = UIImageJPEGRepresentation(theImage, 0.5f);
                    [image writeToFile:[placeCategoryPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@",[placesTitle[j] stringByReplacingOccurrencesOfString:@"/" withString:@""]]] atomically:YES];
                    currentCount++;
                }
                else
                    continue;              
            }
        }
        else
            continue;
    }

}

希望你能帮助我。

0 个答案:

没有答案