ios - UIButton 在 UITableview 中不起作用

标签 ios iphone uitableview uibutton

enter image description hereUITableviewcell --> 在其中我有 4 个不同的 UIView,其中 3 个 View 有 UIButtons。我想让 UIButton 可以点击。第一次可以点击按钮,但是当我转到下一个屏幕并返回时,按钮不起作用。请让我知道如何实现这个?谢谢!

PHMyTripView *tripsView=[[PHMyTripView alloc] initWithFrame:CGRectMake(10, 5, self.frame.size.width-20, cell.frame.size.height)];

                         tripsView.onBaggageClick = ^{
                             [weakSelf handleBaggagePurchaseTapped];
                         };

                         if ([data count]>0) {
                             [tripsView fillTripData:[data firstObject]];
                             [tripsView showAncillaries:self.predictiveManager.upcomingCDAirBookingInfo];
                         }
                         [cell bringSubviewToFront:tripsView.bagsButton];
                         [cell.viewPlaceHolder addSubview:tripsView];

最佳答案

发生这种情况是因为单元格是可重复使用的,如果您转到另一个屏幕,按钮可能会在 UI 或功能上混入不同的单元格。

解决这个问题的方法是添加标签。你可以定义 cell.tag = indexPath.row * 10 左右。

然后在绘制按钮时,检查条件,如果 cell.tag == ?,则添加按钮。

关于ios - UIButton 在 UITableview 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38404368/

相关文章:

ios - 表格单元格自动布局的问题没有按照我想要的方式间隔

ios - 从 coredata 获取父子数组

iphone - 从 Xcode(以及在 Instruments 中)在 iPhone 上运行 iPhone 应用程序时出现问题

iphone - 为 iPhone 应用程序创建华丽的介绍

ios - 图像目录中矢量 pdf 的渲染模式设置为模板,但 UIImageView 不会在自定义单元格中为图像着色

ios - 调整大小的UITableViewCell : toggling UITextView in UITableViewCell by using auto layouts

.net - 声明 ClientBase 期间设备崩溃

iphone - 如何从 TTLauncher/Three20 中删除项目?

ios - 如何使用 Storyboard在另一个 Controller 中 subview UITableViewController

ios - 无法在 TableView Controller 中扩展 TableView 单元格的高度