gpt4 book ai didi

iOS Xcode Swift 将输入名字和姓氏组合成全名问题

转载 作者:行者123 更新时间:2023-11-30 13:10:30 25 4
gpt4 key购买 nike

我在组合我正在运行的代码以将其更新到 TableView 单元的名字和姓氏时遇到问题。似乎它没有保存名字或姓氏,只是在我输入新文本时替换它。我不确定发生了什么,并且我确定我在 .plist 中使用的行号与代码。对于此或其他替代方案的任何帮助,我们将不胜感激。

func textfieldTextWasChanged(newText: String, parentCell: CustomCell) {
let parentCellIndexPath = tblExpandable.indexPathForCell(parentCell)

let currentFullname = cellDescriptors[0][12]["primaryTitle"] as! String
let fullnameParts = currentFullname.componentsSeparatedByString(" ")

var newFullname = ""

if parentCellIndexPath?.row == 13 {
if fullnameParts.count == 2 {
newFullname = "\(newText) \(fullnameParts[1])"
}
else {
newFullname = newText
}
}
else {
newFullname = "\(fullnameParts[0]) \(newText)"
}

cellDescriptors[0][12].setValue(newFullname, forKey: "primaryTitle")
tblExpandable.reloadData()
}

最佳答案

最有可能发生的情况是,当您调用 tblExpandable.reloadData() 时,将调用 cellForRowAtIndexPath,并且它会覆盖您在此处所做的更改。您要么需要进行一些单元格缓存,要么可能考虑使用 UIScrollView 而不是 UITableView。

关于iOS Xcode Swift 将输入名字和姓氏组合成全名问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38780725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com