Я пытаюсь получить новую строку внизу, как «вставить новую ячейку» с кнопкой «плюс» слева в UITableView, когда пользователь нажимает кнопку редактирования и уходит, когда пользователь нажимает кнопку «done» , Прямо сейчас я получаю кнопку «плюс» в последней строке таблицы, но я не могу динамически добавить новую строку. Может ли кто-нибудь помочь, что мне делать, или это их лучший способ сделать это?Новая строка при нажатии кнопки редактирования в UITableViewin swift
Я пошел в этот ответ на переполнение стека Using insert rows in a UITableView , но я не получаю
NSMutableArray* paths = [[NSMutableArray alloc] init];
, что это утверждение для.
Это мой код
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if self.tableView.editing == true {
return nameArray.count + 1
}
else
{
return nameArray.count
}
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as UITableViewCell
if indexPath.row >= nameArray.count
{
cell.textLabel?.text = "insert new row"
}
else
{
cell.textLabel?.text = nameArray[indexPath.row]
}
cell.showsReorderControl = true
return cell
}
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
if editingStyle == .Delete {
nameArray.removeAtIndex(indexPath.row)
tableView.deleteRowsAtIndexPaths([indexPath], withRowAnimation: .Fade)
}
else if editingStyle == .Insert{
self.performSegueWithIdentifier("insertNameSegue", sender:nil)
}
}
override func setEditing(editing: Bool, animated: Bool) {
super.setEditing(true, animated: true)
self.tableView.setEditing(true, animated: true)
tableView.reloadData()
}
Вы должны реализовать 'didSelectRowAtIndexPath' - в этом метод проверки, если вы редактируете, и если это была последняя «добавленная» строка, которая была выбрана, - если это так, выполните ваш переход к представлению вставки – Paulw11