gpt4 book ai didi

iphone - 在 didSelectRowAtIndexPath 中的单元格上找到一个确切的 UIImageView

转载 作者:行者123 更新时间:2023-11-28 22:47:18 24 4
gpt4 key购买 nike

在我的 cellForRowAtIndexPath 中

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
//...do cell setup etc.

UIImage *iconthumbNail = [UIImage imageNamed:@"icon.png"];
UIImageView * iconimgView = [[UIImageView alloc] initWithFrame:CGRectMake(265, 34, 25, 25)];
[iconimgView setImage:iconthumbNail];
//imgView.image = thumbNail;
[cell addSubview:iconimgView];
[iconimgView release];
// add a few more UIImageViews to the cell
}

那么在我的

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:NO];

UITableViewCell * theCell = [tableView cellForRowAtIndexPath:indexPath];

for (UIView * b in cell.subviews)
{
if ([b isKindOfClass:[UIImageView class]])
{
// how do I check that its 'iconImgView' so that I can change it?
}
}

因此,我在我的 cellForRowAtIndexPath 中添加了一个 UIImageView,然后当该表格单元格被选中时,我想更改单元格中的一个图像“iconImgView”,但是我如何从该单元格中存在的其他 UIImageViews 中识别这个 UIImageView?

非常感谢,-代码

最佳答案

我不会使用这种方法,而是会为您要查找的 UIImageView 分配一个标签。

iconimgView.tag = 1;

然后在 didSelectRowAtIndexPath 方法中,使用这个:

UIImageView *iconimgView = (UIImageView *)[cell viewWithTag:1];

如果你还是想按照自己的方式去做,你可以这样做:

if ([b isKindOfClass:[UIImageView class]]) {
UIImageView *myView = (UIImageView *)b;
if ([b.image isEqual:[UIImage imageNamed:@"yourImageName"]]) {
// Do your stuff
}
}

关于iphone - 在 didSelectRowAtIndexPath 中的单元格上找到一个确切的 UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12873959/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com