为啥在 iOS 13 中的 textfieldBeginEditing 之后立即调用 textfieldDidEndEditing?在 iOS 较低版本中运行良好
Posted
技术标签:
【中文标题】为啥在 iOS 13 中的 textfieldBeginEditing 之后立即调用 textfieldDidEndEditing?在 iOS 较低版本中运行良好【英文标题】:Why does textfieldDidEndEditing getting called immediately after textfieldBeginEditing in iOS 13? Works Fine in iOS lower versions为什么在 iOS 13 中的 textfieldBeginEditing 之后立即调用 textfieldDidEndEditing?在 iOS 较低版本中运行良好 【发布时间】:2019-10-01 07:30:48 【问题描述】:我想编辑文本字段的文本并在用户在集合视图单元格上向左滑动并单击重命名时保存它。所以每当单击重命名时我都会写 cell.textfield.becomefirstresponder() ..然后在处理的情况下textfield 委托方法,首先调用 textDidBeginEditing ,然后甚至不做任何事情,调用 textfieldDidEndEditing 退出响应者状态。它仅在 ios 13 中发生
public func textFieldDidBeginEditing(_ textField: UITextField)
self.emptyView.isHidden = true
public func textFieldDidEndEditing(_ textField: UITextField, reason: UITextFieldDidEndEditingReason)
setChangedValues(selectedTextField: textField)
public func textFieldShouldReturn(_ textField: UITextField) -> Bool
//setChangedValues(selectedTextField: textField)
textField.resignFirstResponder()
return true
public func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool
if range.location == 0 && string == " "
return false
//Fix:- when u remove the text completely and still textfield contains the last character
if range.location == 0 && string == ""
textField.text = ""
//Setting the limit
var maxLimit = 50
if textField.tag == 2
maxLimit = 15
let newLength = (textField.text?.count)! + string.count - range.length
if newLength <= maxLimit
//If new character is typed
else
//If the entered character is more than the limit, return false
return newLength<=maxLimit
return true
func setChangedValues(selectedTextField: UITextField)
if (selectedTextField.text?.isEmpty)!
assetsTableView.reloadData()
else
var assetModels = Array<FHTeamAssetsModel>()
if isEdit
//Both are different, please update
if selectedTextField.text != assetsList[selectedAsset!][WPEConstants.ASSET__NAME]!
//Getting the asset based on asset list selection
let asset = FHBase.getAssetModel(id: assetsList[selectedAsset!][WPEConstants.ASSET__ID]!)
asset.name = selectedTextField.text
FHBase.updateTeamAssets(model: asset)
if selectedPath > 0
//Getting the updated sub asset list
assetModels = FHBase.getTeamAssetsModels(assetId: assetsPathArray[selectedPath][WPEConstants.ASSET_ID])
else
//Getting the updated asset list(without assetId)
assetModels = FHBase.getTeamAssetsModels(assetId: nil)
else
if selectedPath > 0
//Creating a new sub-asset, with assetId
FHBase.shared.createAssetsModel(name: selectedTextField.text, assetId: assetsPathArray[selectedPath][WPEConstants.ASSET_ID], assetName: assetsPathArray[selectedPath][WPEConstants.ASSET_NAME])
//Getting the updated sub asset list
assetModels = FHBase.getTeamAssetsModels(assetId: assetsPathArray[selectedPath][WPEConstants.ASSET_ID])
else
//Creating a new asset(without assetId)
FHBase.shared.createAssetsModel(name: selectedTextField.text, assetId: nil, assetName: nil)
//Getting the updated asset list(without assetId)
assetModels = FHBase.getTeamAssetsModels(assetId: nil)
//Creating asset list
self.createAssetsList(assetModels: assetModels)
assetsTableView.reloadData()
self.isEdit = false
self.updateEmptyStateUI()
【问题讨论】:
我也在为类似的问题而苦苦挣扎,仅在 iOS 13 上也是如此...... 【参考方案1】:检查是否有人禁用了 textField!
【讨论】:
以上是关于为啥在 iOS 13 中的 textfieldBeginEditing 之后立即调用 textfieldDidEndEditing?在 iOS 较低版本中运行良好的主要内容,如果未能解决你的问题,请参考以下文章
为啥需要在 pageControl 中为 iOS 13 和 iOS 14 设置不同的常量
为啥在 32 位架构的 iOS 13 上出现 iOS Sticker 应用警告? TMS-90747
为啥 UICollectionView 在 Xcode 11 (ios 13) 中省略 Line/Intrim 间距?