2016-08-05 32 views
0

我無法將此代碼的名字和姓氏組合起來,以便將其更新爲tableviewcell。看起來好像它沒有保存名字或姓氏,只是在我輸入新文本時將其替換。我不確定發生了什麼,我確定我在.plist中使用的行號與碼。任何幫助這個或其他的替代品,表示讚賞。iOS Xcode Swift將輸入姓名和姓氏合併爲FullName問題

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() 
} 

回答

0

什麼最有可能的情況是,當你調用tblExpandable.reloadData()的cellForRowAtIndexPath獲取調用,它改寫了,你在這裏做的更改。您需要執行一些單元緩存或可能考慮使用UIScrollView而不是UITableView。