2

我的应用程序将查询数据库 50 次,然后通过将正确的 UIImageView 添加到另一个 UIImageView 来做出相应的反应,然后我希望应用程序在每个循环中立即显示。

唉,经过很多个晚上,我都没有让它工作。应用程序不会立即显示 UIImageView。话虽如此,当我在循环中放大或缩小时,UIImageViews 会出现!我肯定错过了什么...

到目前为止,除了最后一部分 [UIScrollView performSelector....

请帮助并提前感谢您。

    UIScrollView *firstView;
    UIImageView *secondView;
    UIImageView *thirdView;
    NSOperationQueue *queue;
    NSInvocationOperation *operation;

    - (void)viewDidAppear:(BOOL)animated
    {
    queue = [NSOperationQueue new];
    operation = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(getData) object:nil];
    [queue addOperation:operation];
    }

    - (void) getData
    {
     for (i=0 ; i < 50 ; i++)

         {

            //All the codes to facilitate XML parsing here
            [nsXMLParser setDelegate:parser];
            [BOOL success = [nsXMLParser parse];

            if (success) 
            {   

                if ([parser.currentValue isEqualToString:@"G"])

                thirdView.image = greenTick.jpg;
                [secondView addSubview:thirdView];

            } 
            else 
            {
                NSLog(@"Error parsing document!");
            }
    } 
    [thirdView performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone: YES];
}
4

1 回答 1

2

我发现了解决方案,并真正希望这对某人有所帮助...

        if (success) 
        {   

            if ([parser.currentValue isEqualToString:@"G"])

            // Make the changes here - start
            dispatch_queue_t main_queue = dispatch_get_main_queue();
            dispatch_async(main_queue, ^{
            thirdView.image = greenTick.jpg;
            [secondView addSubview:thirdView];
            });
            // Make the changes here - end
        } 
        else 
        {
            NSLog(@"Error parsing document!");
        }
} 
// Remove performSelectorOnMainThread 
于 2012-11-23T01:44:36.580 回答