gpt4 book ai didi

iphone - UITableview 的滚动改变了 UIButton 的图像,UITableview 滚动问题

转载 作者:可可西里 更新时间:2023-11-01 17:09:20 26 4
gpt4 key购买 nike

我正在做的是,我有一个 UITableview 并且我添加了 UIButton 作为自定义 View 。我正在为每个按钮提供标签,标签 已在操作方法中收到。当我按下按钮时,它会更改选定和未选定按钮的图像,但当我滚动它时,它将进入正常状态。

这是我在索引方法下的行单元格

static NSString *CellIdentifier = @"Cell4";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [self tableviewCellWithReuseIdentifierFollowing:CellIdentifier];
}
followingButton = [UIButton buttonWithType:UIButtonTypeCustom];
[followingButton addTarget:self action:@selector(followingButtonpressed:)forControlEvents:UIControlEventTouchUpInside];
[followingButton setImage:[UIImage imageNamed:@"following12.png"] forState:UIControlStateNormal];
followingButton.frame = CGRectMake(220.0 ,20.0, 100, 40.0);
[cell.contentView addSubview:followingButton];
NSLog(@"row--%d",indexPath.row);
followingButton.tag=indexPath.row;
NSLog(@"followingButton.tag--%d",followingButton.tag);
[self configureCellFollowing:cell forIndexPath:indexPath];
return cell;
}

==================

//Here is the action method

-(void)followingButtonpressed:(id)sender
{
NSLog(@"sender tag --%d",[sender tag]);
UIButton *btnPly = (UIButton *)sender;
if([btnPly isSelected])
{
[btnPly setSelected:NO];
[btnPly setImage:[UIImage imageNamed:@"following12.png"] forState:UIControlStateNormal];
}
else
{
[btnPly setSelected:YES];
[btnPly setImage:[UIImage imageNamed:@"following_off12.png"] forState:UIControlStateNormal];
}
}

最佳答案

注意:此代码为每行数据创建单元格(不重用单元格)

您只需要按照描述进行更改,可能对您有所帮助

NSString *CellIdentifier = [NSString stringWithFormat:@"S%1dR%1d",indexPath.section,indexPath.row];

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

可能会解决您的问题:)

关于iphone - UITableview 的滚动改变了 UIButton 的图像,UITableview 滚动问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14401231/

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