gpt4 book ai didi

ios - 如何更改表格 View 单元格图像?

转载 作者:行者123 更新时间:2023-11-29 03:31:37 28 4
gpt4 key购买 nike

我在侧边栏中有类似于 Facebook 应用程序的表格 View 。在我的侧边栏表格 View 中,每一行都有 ImageView 。我希望当我单击单元格时 ImageView 会发生变化,并且在选择另一个单元格时它将保留。这是我的代码

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]autorelease];
}
[[cell.contentView subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];

UIView * contentView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 60)];

UIImageView * cellImg = [[UIImageView alloc]initWithFrame:CGRectMake(5,8,259, 60)];
[cellImg setImage:[UIImage imageNamed:[menuArr objectAtIndex:indexPath.row]]];
[contentView addSubview:cellImg];

[contentView setBackgroundColor:[UIColor clearColor]];
[cell.contentView addSubview:contentView];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}

#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
delegate.sideBarSelectedIndex = indexPath.row;
NSLog(@"delegate.sideBarSelectedIndex: %d",delegate.sideBarSelectedIndex);

[UIView commitAnimations];
if (self.sidebarDelegate) {
NSObject *object = [NSString stringWithFormat:@"ViewController%d", indexPath.row];
[self.sidebarDelegate sidebarViewController:self didSelectObject:object atIndexPath:indexPath];
[delegate.firstLensePageObj timerFunction:indexPath.row];
}

}

最佳答案

在您的 didSelectRowAtIndexPath 委托(delegate)方法中尝试一下:-

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.imageView.image = [UIImage imageNamed:@"yourImage"];

关于ios - 如何更改表格 View 单元格图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19699190/

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