【发布时间】:2011-06-16 04:11:41
【问题描述】:
我通过单击按钮在我的表格视图中加载一些图像。图像加载良好并且在所需的位置。但是当我滚动表格视图时,图像似乎发生了变化。让我详细说明只有 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++;
}
我们将不胜感激。
谢谢, 克里斯蒂
【问题讨论】:
-
setImage1:是如何实现的?
标签: objective-c xcode ipad uitableview