如何禁用调用UITableViewCell某些部分的DidSelect?
问题描述:
由于我的单元格可以在水龙头上进行扩展,并且在可扩展部分中包含两个按钮,所以当用户点击这些按钮以改进用户体验时,我想使DidSelect/DidDeselect不被调用。如何禁用调用UITableViewCell某些部分的DidSelect?
这些按钮放置在另一个UIView内的StackView中。
我试过两个stackView和UIView的容器禁用用户交互,但结果是一样的。
你会推荐什么来禁用整个UIView容器(请注意,这是我的单元格的一部分)在点击时调用DidSelect/DidDeselect?
答
尝试执行stackView
中这两个按钮的操作。
// inside cellForRowAt indexPath
cell?.button1.tag = indexPath.row
cell?.button1.addTarget(self, action: #selector(defineTypeAction(_:)), for: .touchUpInside)
各自的行动:
func defineTypeAction (_ sender: UIButton){
let alert=UIAlertController(title: kAppName, message: "Select", preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: {(action:UIAlertAction) in
sender.setTitle("your title", for: .normal)
// your custom code
}));
present(alert, animated: true, completion: nil)
}
当您点击按钮的操作方法将被调用,而不是tableView
委托方法。
完全禁用选择,并在单元格本身中执行选择,但仅限于您希望选择的部分。 –
您可以将这些按钮放在另一个尺寸较大的视图上。 – vaibhav
@vaibhav他们已经放在视图中,看到 – DCDC