iOS Xcode Swift将输入FirstName和LastName组合成FullName问题

时间:2016-08-05 03:42:06

标签: ios swift xcode tableview

我在运行此代码的名字和姓氏时遇到问题我正在运行以将其更新为tableviewcell。似乎它没有保存名字或姓氏,只是在我键入新文本时替换它。我不确定发生了什么,我确定我在.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()
}

1 个答案:

答案 0 :(得分:0)

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