0

我有课LoadViewController,一开始我称之为:

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.

dispatch_async(kBgQueue, ^{

    NSData *dataOfURL = [NSData dataWithContentsOfURL:kRSSURL];

    [self performSelectorOnMainThread:@selector(fetchedData:) withObject:dataOfURL waitUntilDone:YES];
});
}

kbgQueue在哪里

   #define kBgQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)

在主线程上执行fetchedData:

- (void)fetchedData:(NSData *)responseData {

XMLParser *parser = [[XMLParser alloc] initWithData:responseData];
parser.delegate = self;

if ([parser parse]) {

    // if parsed.
    if (!data) {

        data = [[NSMutableArray alloc] init];
    }
    else {

        [data removeAllObjects];
    }

    data = [parser getParsedData];

    ViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"ViewController"];
    viewController.array = data;

    [self presentViewController:viewController animated:YES completion:^{}];
    //[self reloadData];
}
else {

    NSLog(@"False.");
}

}

如您所见,我使用自己的XMLParser帮助程序类,在其中获取所有数据。当下载一条数据时,我[self.delegate passProgress:fetchedItems/20.0f];由委托人调用,并且LoadViewController是这样的:

-(void)passProgress:(float)progress {

dispatch_async(dispatch_get_main_queue(), ^{
    [self.progressView setProgress:progress];
    NSLog(@"Updated!");
});
}

但问题是:下载了 20 个数据项中的一个后,progressView 没有更新。哪里有问题?

4

1 回答 1

0

我不知道它是否正确,但我LoadViewController从更改perfromOnMainThread:withObject:waitUntilDone:perfromInBackground:withObject:,但它有效。

于 2012-12-05T12:58:25.587 回答