單擊按鈕,我在表格視圖中加載一些圖像。圖像加載正常並位於所需的位置。但當我滾動表格視圖時,圖像似乎會發生變化。讓我詳細說明了在我的表視圖中最初只有2行可見,並假設圖像在兩行中存在,並且在一行中有4個圖像。現在,當我向下或向上滾動表視圖時,在表格上方或下方滾動的行視圖框架將在其圖像視圖中顯示新圖像。並且每次當我滾動圖像不斷變化時。可能是什麼原因。我正在用這個抓我的頭。請幫助。我發佈了我的代碼的一部分: -在滾動時顯示不同圖像的表格視圖
-(UITableViewCell*)tableView(UITableView*)
ableViewcellForRowAtIndexPath(NSIndexPath*)indexPath {
UITableViewCell *cell = nil;
static NSString *AutoCompleteRowIdentifier = @"AutoCompleteRowIdentifier";
cell = [tableView dequeueReusableCellWithIdentifier:AutoCompleteRowIdentifier];
if (cell == nil) {
cell=[[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:AutoCompleteRowIdentifier] autorelease];
}
UIImageView * imageView1 = [[[UIImageView alloc] initWithFrame:CGRectMake(25, 4, 80, 80)] autorelease];
UIImageView * imageView2 = [[[UIImageView alloc] initWithFrame:CGRectMake(115,4,80, 80)] autorelease];
UIImageView * imageView3 = [[[UIImageView alloc] initWithFrame:CGRectMake(205,4, 80, 80)] autorelease];
UIImageView * imageView4 = [[[UIImageView alloc] initWithFrame:CGRectMake(295,4, 80, 80)] autorelease];
imageView1.tag = 1;
imageView2.tag = 2;
imageView3.tag = 3;
imageView4.tag = 4;
[cell.contentView addSubview:imageView1];
[cell.contentView addSubview:imageView2];
[cell.contentView addSubview:imageView3];
[cell.contentView addSubview:imageView4];
UIImageView * imageView;
for (int i = 1; i <= 4; i++) {
imageView = (UIImageView *)[cell.contentView viewWithTag:i];
imageView.image = nil;
}
int photosInRow;
if ((indexPath.row < [tableView numberOfRowsInSection:indexPath.section] - 1) ||
(count % 4 == 0)) {
photosInRow = 4;
} else {
photosInRow = count % 4;
}
for (int i = 1; i <= photosInRow; i++) {
imageView = (UIImageView *)[cell.contentView viewWithTag:i];
[self setImage1:imageView];
}
return cell;
}
-(void)setImage1:(UIImageView *)imageView
{
UIImageView *imageView1=[[UIImageView alloc]init];
imageView1=imageView;
imageView1.image = [UIImage imageNamed:[NSString stringWithFormat:@"%d.png", j]];
j++;
}
任何幫助wi將不勝感激。
感謝, 克里斯蒂
如何'setImage1:'執行? – 2011-06-16 04:38:37
看到我編輯的問題 – Christina 2011-06-16 05:09:11
編輯我的答案。 – 2011-06-16 05:17:09