UIButton突出显示,但不执行其操作

我有一个带有不同行的tableView。其中大多数填充有包含TextFields的单元格,最后一个是包含UIStackView的单元格,其中显示了两个UIButton。基本上,我的目标是拥有一个像窗体一样工作的tableView,每行将获取一些信息,最后,当用户单击底部的两个按钮之一时,所有信息均被保存(另一个按钮应取消操作并获取返回上一个视图)。 现在,所有文本字段都运行良好,并且在“空闲”状态下,按钮也运行良好,并且可以执行所需的操作。

问题如下:在textField之一的编辑模式下,如果我单击底部的按钮之一,则它们将突出显示(因此正在发生某些事情),但是它们不执行操作。接下来发生的事情是键盘被关闭了(textField从第一响应者辞职了),然后全部回到“空闲状态”。此时,按钮恢复正常工作(因此,如果再次单击它们,将执行其操作等)。

即使它们的焦点在其他单元格的编辑模式上,我也希望它们能够工作,并且我不希望用户被迫单击两次相同的按钮。 我该怎么办?

我已经尝试了tableView,UIButton甚至StackView的所有可能的属性(因此“ isInteractionEnabled”,“ AllowsMultipleSelectionWhileEditing”,“ delaysContentTouches”等“ BringSubviewToFront”。) 我不知道为什么该按钮高亮显示但不起作用。

混合中还有一个tapGestureRecognizer,但似乎没有参与(每次调用时我都会打印一些东西,事实并非如此)。

这是我的代码。

在ButtonCell初始化中:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="checkbox" id="changeclass" /><br/>
<div id="myDiv">
  Hello World
</div>

在viewDidLoad方法中:

modButton.addTarget(self,action: #selector(modClicked()),for: .touchUpInside)
saveButton.addTarget(self,action: #selector(saveclicked()),for: .touchUpInside)
//some other properties of the buttons

buttonStack.alignment = .center
buttonStack.axis = .horizontal
buttonStack.distribution = .equalSpacing
buttonStack.translatesAutoresizingMaskintoConstraints = false

buttonStack.addArrangedSubview(modButton)
buttonStack.addArrangedSubview(saveButton)

addSubview(buttonStack)
//some constraints

在tableView cellForRow方法中:

let tap: UITapGestureRecognizer = UITapGestureRecognizer(target: self,action: #selector(screenTouched))
tap.cancelsTouchesInView = false
view.addGestureRecognizer(tap)

//some properties i've tried

tableView.delegate = self
tableView.dataSource = self
tableView.separatorColor = .clear
tableView.isScrollEnabled = false
tableView.delaysContentTouches = false
tableView.allowsSelection = true
tableView.allowsSelectionDuringEditing = true
tableView.allowsMultipleSelectionDuringEditing = true
asdz321 回答:UIButton突出显示,但不执行其操作

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3124476.html

大家都在问