1

1.私のmainViewはUIScrollViewです。9枚の画像をタイルとしてロードする必要があります。

2. 9imagesを取得し、それをインターフェイス(メインスレッド)にロードするために、関数を別のスレッドとして呼び出しています。そうすることで、インターフェイスの応答性が維持されます。

3.しかし、画像がロードされている場合でも、スレッド全体が完了するまで、画像がUIScrollViewに表示されないという問題があります。しかし、インターフェイスで何らかのアクションを実行している場合は、それぞれがロードされて表示されているのを確認できます。

  1. つまり、各画像がロードされた後、バックグラウンドスレッドからインターフェイス(メインスレッド)を更新する必要があります。

どうすればいいですか?別のスレッドを使用して呼び出すUIScrollViewに画像をロードするために使用するコードを指定しました。

- (void)setUpDisplay:(NSArray *)array 
{
NSAutoreleasePool *pool=[[NSAutoreleasePool alloc] init];

myScrollView.userInteractionEnabled = YES;
myScrollView.multipleTouchEnabled = YES;

int x=0,y=0;
CGRect frame;
for (i = 0; i < 3; i++)
{
    if(j == 3)
    {
        x=x+256;
        y = y-768;
    }
    for (j = 0; j < 3; j++) {
        imageView = [[UIImageView alloc] initWithImage:[self getCachedImage:[NSString stringWithFormat:@"url to fetch images"]]];
        frame = [imageView frame];
        frame.origin.x = x;
        frame.origin.y = y;
        [imageView setFrame:frame];
        imageView.userInteractionEnabled = YES;
        imageView.multipleTouchEnabled = YES;
        [myScrollView addSubview:imageView];
        y = y+256;

        [imageView release];
        imageView=nil;
    }
}

[pool release];
}
4

2 に答える 2

2

NSObject のこのメソッドは、しばしば役に立ちます:

[someObject performSelectorOnMainThread:@selector(updateUI:) withObject:anotherObject waitUntilDone:YES /* or NO */];
于 2010-01-13T06:31:45.353 に答える
0

各画像の読み込みが終了したら、メイン スレッドで [myScrollView setNeedsDisplay] を呼び出してみてください。

于 2010-01-13T07:19:30.047 に答える