问题描述
点击一个按钮,要清空一个cell的数据,但是reload没有清空。如图
点击物业管理处,要清空公司名称,但是没有如图
解决过程:
1.查看代码并debug发现在点击按钮的时候的确已经执行了清空操作
func radioReturn(type:OutRegisterSubmitRadioCellType) {
debugPrint("传过来的radiocelltype数据 \(radiocelltype.rawValue)")
self.radiocelltype = type
//清空公司名称
var model = self.promptlist[0]
model.infoValue = ""
if self.radiocelltype == .manage {
model.mustEnter = false
}else{
model.mustEnter = true
}
self.promptlist[0] = model
self.tableView.reloadData()
}
tableView
但是debug到tableView(at)的时候,发现还是数据还在。2.发现点击按钮的时候键盘还在,猜测是reloaddata时,键盘事件才执行消失,相当于把键盘的数据又重新写到了那个里面,验证发现的确是这样,如图
解决方案:
找到点击按钮事件,执行取消第一响应者即可
//取消第一响应者相应事件
UIApplication.shared.sendAction(#selector(resignFirstResponder), to: nil, from: nil, for: nil)
项目代码修改为:
func buttonClick(_ sender:RadioButton) {
//取消第一响应者相应事件
UIApplication.shared.sendAction(#selector(resignFirstResponder), to: nil, from: nil, for: nil)
var returntype:OutRegisterSubmitRadioCellType
switch sender.tag {
case 1001:
returntype = .outsource
case 1002:
returntype = .specified
case 1003:
returntype = .manage
default:
returntype = .outsource
}
if self.raidoReturnB != nil {
self.raidoReturnB!(returntype)
}
}