有 UITableviewcell
--> 在其中我有 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/