I want to insert in textfields in specific cells of the tableview. I have an array of 12 strings (3 of which are empty spaces). Those blank cells in the tableview, I want to create a text field in them so user can type in those empty slots. But I am having trouble creating text fields only in those slots which are blank. How should I do that?
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
}
}
here is how i reload the cells. now the text field is showing but it begins to show in cells where string is non-empty spaces.
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()
}