我想插入到tableview的特定单元格的文本字段中。我有12个字符串的数组(其中3个是空的空格)。在tableview中的那些空白单元格中,我想在它们中创建一个文本字段,以便用户可以键入这些空白插槽。但是,我仅在那些空白的插槽中创建文本字段时遇到问题。我应该怎么做?在tableview的特定单元格中创建文本字段
var items = ["Apple", "Fish", "Dates", "Cereal", "Ice cream", "Lamb", "Potatoes", "Chicken", "Bread", " ", " "," "]
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("cellFruit", forIndexPath: indexPath)
if (items[indexPath.row] == " ") {
cell.textLabel?.text = items[indexPath.row]
let collar = UIColor.init(red: 175, green: 189, blue: 212, alpha: 0.4)
cell.backgroundColor = collar
return cell
}
else {
cell.textLabel?.text = items[indexPath.row]
let coL = UIColor.init(red: 59, green: 89, blue: 152, alpha: 0.2)
cell.backgroundColor = coL
return cell
}
}
这里是我如何重新加载单元格。现在文本字段正在显示,但它开始在单元格中显示字符串是非空的空格。
func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
if (sourceIndexPath.row != destinationIndexPath.row){
let temp = items[sourceIndexPath.row]
items.removeAtIndex(sourceIndexPath.row)
items.insert(temp, atIndex: destinationIndexPath.row)
}
tableView.reloadData()
}
到目前为止你有什么?请粘贴一些代码.. – tbilopavlovic
首先获取数组值并检查值是否为空。如果它为空,则将您的文本字段添加到单元格。否则,添加字符串值。 – Signare
@ user1941284我刚刚发布了代码。 items是我用来创建行的数组的名称。 –