UIImageView не обновляется - PullRequest
       4

UIImageView не обновляется

0 голосов
/ 24 февраля 2011

У меня проблема с моим UIImageView, который не обновляется.Итак, это так: у меня есть UIScrollView, который содержит UIImageView (называемый imageView).Теперь imageView должен содержать больше UIImageViews.Те UIImageViews, которые я добавляю из кода, но они не появляются.

Это код:

    for(i = 0 ; i < NrOfTilesPerHeight ; i++)
    for(j = 0 ; j < NrOfTilesPerWidth ; j++)
    {               
         imageRect = CGRectMake(j*TILE_WIDTH,i*TILE_HEIGHT,TILE_WIDTH, TILE_HEIGHT);
         image = CGImageCreateWithImageInRect(aux.CGImage, imageRect);

         if(!data[i][j])
        NSLog(@"data[%d][%d] is nil",i,j);

         context = CGBitmapContextCreate (data[i][j], TILE_WIDTH, TILE_HEIGHT, 
                         bitsPerComponent, bitmapBytesPerRow, colorSpace,
                         kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);

         if (context == NULL)  
         {
          free (data);
          printf ("Context not created!");
          CGColorSpaceRelease( colorSpace );
         }

         CGContextDrawImage(context, CGRectMake(0, 0, TILE_WIDTH, TILE_HEIGHT), image);

         data[i][j] = CGBitmapContextGetData (context);
         memcpy(originalData[i][j],data[i][j],TILE_WIDTH*TILE_HEIGHT*numberOfCompponents);

         CGContextFlush(context);

         CGImageRelease(image);

         UIImageView *imgView = [[UIImageView alloc] init];
         [imgView setTag:i*10+j];

         CGRect frame = imgView.frame;
         frame.origin.x = j * (TILE_WIDTH+5)  * initialScale;
         frame.origin.y = i * (TILE_HEIGHT+5) * initialScale;
         frame.size.width  *= initialScale;
         frame.size.height *= initialScale;

         [imgView setFrame:frame];

         [imageView addSubview:imgView];

         [self updateTileAtLine:i andRow:j];

         [imgView release];
         CGDataProviderRelease(dataProvider);
         CGImageRelease(cgImage);        
    }



- (void) updateTileAtLine: (int) i andRow: (int) j
{           
    CGDataProviderRef dataProvider = CGDataProviderCreateWithData(NULL, data[i][j], bitmapByteCount, NULL);

    CGImageRef cgImage = CGImageCreate(TILE_WIDTH, TILE_HEIGHT, bitsPerComponent,
               bitsPerPixel, bitmapBytesPerRow, colorSpace,           kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big, dataProvider, NULL, false,  kCGRenderingIntentDefault);

    UIImage *myImg = [UIImage imageWithCGImage:cgImage];
    UIImageView *auxImageView = (UIImageView*) [imageView viewWithTag:(i*10+j)];
    [auxImageView setImage:myImg];

    CGDataProviderRelease(dataProvider);
    CGImageRelease(cgImage);
}

Теперь ... это не дает сбой ... так что все не нольи хорошоЕсли вместо использования viewWithTag я выделю init новый UIImageView и добавлю его в imageView, он появится.Но я не хочу делать еще одну копию представления, поскольку этот метод updateTile будет вызываться довольно часто.

Мой вопрос: почему не появляется auxImageView?Это очень должно.

Спасибо.

С уважением, Джордж

1 Ответ

1 голос
/ 24 февраля 2011

Попробуйте это

for(UIView *view in [imageView subviews]) {
if(view.tag == i*10+j) {

UIImageView *auxImageView = (UIImageView*) view;
[auxImageView setImage:myImg];
}

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...