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 に答える