2011-06-20 53 views
1

我想在視圖上顯示縮略圖圖像。 我正在使用以下方法將圖像添加到縮略圖。圖像取自數據庫在iPhone上顯示多個圖像縮略圖時UI失真

當我添加一個圖像時,一切工作正常。但是,如果我把這個方法在一個循環中添加多張圖片,奇怪的事情發生(UI被扭曲和屏幕的某部分變黑,不僅爲這個應用程序甚至主屏幕)

在模擬器上,一切工作正常即使我添加了很多圖像。

有沒有人有任何想法,我哪裏出錯?我錯過了什麼嗎?

-(void)addImageThumbnailOnViewWithImageData:(NSData *)imgDataToBeAdded{ 

    UIImageView *imgView; 

    imgView=[[UIImageView alloc] initWithFrame:CGRectMake(tempX, tempY, 70, 70)]; 

    tempX+=80; 
    if (tempX>300) { 
     tempX=10; 
     tempY+=80; 
    } 

    UIImage * newImage = [[UIImage alloc] initWithData:imgDataToBeAdded]; 
    [imgView setImage:newImage]; 

    [self.view addSubview:imgView]; 


    [imgView release]; 

} 

回答

0

UIImageView * imgView;

imgView = [[UIImageView alloc] initWithFrame:CGRectMake(tempX,tempY,70,70)];

tempX + = 80; 如果(tempX> 300){

tempX=10; 

tempY-=80;//i think u have to modify this with - 

}

的UIImage * newImage = [[UIImage的頁頭] initWithData:imgDataToBeAdded];

[imgView setImage:newImage];

[self.view addSubview:imgView];

[imgView release];

}

+0

你能解釋一下爲什麼嗎?因爲這個代碼在模擬器上工作得很好,所以我不認爲X和Y值有任何問題 – TheBlackPearl

+0

你已經添加了圖像幀,並且從+向上添加了圖像。我已經修正了它們 –

相關問題