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

iphone – UITableview的滚动改变了UIButton,UITableview滚动问题的图像,第1张

概述我正在做的是,我有一个UITableview,我添加了UIButton作为自定义视图.我给每个按钮添加标签,并在动作方法中收到标签.当我按下按钮时,它会更改所选和未选择按钮的图像,但是当我滚动它时,它将进入正常状态. 这是我在索引方法行的单元格 static NSString *CellIdentifier = @"Cell4";UITableViewCell *cell = [tableVie 我正在做的是,我有一个UItablevIEw,我添加了UIbutton作为自定义视图.我给每个按钮添加标签,并在动作方法中收到标签.当我按下按钮时,它会更改所选和未选择按钮的图像,但是当我滚动它时,它将进入正常状态.

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

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滚动问题的图像全部内容,希望文章能够帮你解决iphone – UITableview的滚动改变了UIButton,UITableview滚动问题的图像所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1000273.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-21
下一篇2022-05-21

发表评论

登录后才能评论

评论列表(0条)

    保存