Ios 在UITableView中设置帧大小图像
我有一个图像大小:Ios 在UITableView中设置帧大小图像,ios,uitableview,Ios,Uitableview,我有一个图像大小:CGRectMake(100,70,50,50)insidecellforrowatinexpath。我需要改变帧大小的图像时,细胞是奇数 代码是: if(indexPath.row %2) { CGRectMake(200,70,50,50) } else { CGRectMake(100,70,50,50) } 在第一次加载TableView时,工作正常,但当我反复滚动时,帧大小的图像显示处于错误位置。它变的很有趣,我不知道为什么 你能帮我吗 非常感谢。您已经在U
CGRectMake(100,70,50,50)
insidecellforrowatinexpath
。我需要改变帧大小的图像时,细胞是奇数
代码是:
if(indexPath.row %2)
{
CGRectMake(200,70,50,50)
}
else
{
CGRectMake(100,70,50,50)
}
在第一次加载TableView
时,工作正常,但当我反复滚动时,帧大小的图像显示处于错误位置。它变的很有趣,我不知道为什么
你能帮我吗
非常感谢。您已经在
UIImageView
子视图上设置了框架:
if(indexPath.row %2) {
cell.yourImageView.frame = CGRectMake(200,70,50,50)
} else {
cell.yourImageView.frame = CGRectMake(100,70,50,50)
}
你可以按照下面的方法做
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UIImageView * imageView;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
if(indexpath.row%2 == 0)
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(200, 70, 50, 50)];
else
{
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(100, 70, 50, 50)];
[cell.contentView addSubview:imageView];
imageView.tag=11;
[imageView release];
}
}
else
{
imageView = (UIImageView*)[cell.contentView viewWithTag:11];
}
// here are couple of other statements
...............
}
就我个人而言,我会创建一个自定义表格单元格并执行如下操作:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"ImageCell";
ImageCell *cell = (ImageCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
[cell configureWithRow:indexPath.row];
}
然后在自定义表格单元格中,为可调整大小的图像视图创建一个IBOutlet,并添加一个方法:
-(void)configureWithRow:(NSInteger)row
{
if(indexPath.row %2)
{
self.resizableImageView.frame = CGRectMake(200,70,50,50)
}
else
{
cell.resizableImageView.frame = CGRectMake(100,70,50,50)
}
}
这有两个作用
你没有设置CGRectMake调用的结果帧…@Bruno Koga:我会怎么做?如何使用?我正在使用情节提要,如果我在UITableView中使用子视图,当我滚动UITableView时,imageview已添加到子视图,imageview已被覆盖。谢谢,我正在使用情节提要中的修复单元。您有解决方案吗?不要使用UITableCell中的单元格,即使您反复滚动此代码也会在正确的位置显示UIImageview。我不明白您的意思,在函数configureWithRow中,我没有得到“Cell.resizebleimageView.frame”