ios – 在UITableView中单击UIButton可点击多个按钮

ios – 在UITableView中单击UIButton可点击多个按钮,第1张

概述当我在UItableView中选择一个按钮时,也会点击下方的其他按钮.我在自定义tableview中的按钮上使用目标 *** 作,并在方法中更改发件人的标题.为什么单击一个按钮选择多个UIButton?任何帮助/建议将不胜感激. 编辑:我正在使用分段的tableview 这是我的代码: - (UITableViewCell *)tableView:(UITableView *)tableView cell 当我在UItableVIEw中选择一个按钮时,也会点击下方的其他按钮.我在自定义tablevIEw中的按钮上使用目标 *** 作,并在方法中更改发件人的标题.为什么单击一个按钮选择多个UIbutton?任何帮助/建议将不胜感激.

编辑:我正在使用分段的tablevIEw

这是我的代码:

- (UItableVIEwCell *)tableVIEw:(UItableVIEw *)tableVIEw cellForRowAtIndexPath:(NSIndexPath *)indexPath {    PosttableVIEwCell *cell = [tableVIEw dequeueReusableCellWithIDentifIEr:@"cell" forIndexPath:indexPath];    // Configure the cell...    [cell.likebutton addTarget:self action:@selector(likebuttonpressed:) forControlEvents:UIControlEventtouchUpInsIDe];    cell.likebutton.tag = indexPath.section;    return cell;}-(voID)likebuttonpressed:(UIbutton *)sender {    NSLog(@"%d",sender.tag);    [sender setTitle:@"pressed" forState:UIControlStatenormal];}
解决方法 在PosttableVIEwCell.h中定义一个Delegate

@protocol HandleCellinteractionDelegate <NSObject>-(voID) dIDPressbutton:(Nsstring*)action forCell:(UItableVIEwCell *)theCell;@end

在tableVIEw.h中注册为此协议的委托

<HandleCellinteractionDelegate>

在tableVIEw.m文件中添加委托处理程序

- (UItableVIEwCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath{    // Create cell    ....    cell.delegate = self;    if (self.qObjects current object's selection state == selected)        enable button    else        disable button }

添加协议功能
    #pragma mark HandleCellinteractionDelegate

-(voID) dIDPressbutton:(Nsstring*)action forCell:(UItableVIEwCell *)theCell{    // Now here you have access to your cell again. And you can update the cell's button text as needed    // Here save selection state in data model.. in self.qObjects <==    cell.questionTextVIEw.text = @"bla bla";}
总结

以上是内存溢出为你收集整理的ios – 在UITableView中单击UIButton可点击多个按钮全部内容,希望文章能够帮你解决ios – 在UITableView中单击UIButton可点击多个按钮所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

    保存