2015-10-20 3 views
1

В моем приложении у меня есть tableView в witch У меня есть текст по умолчанию, и я хотел бы иметь возможность редактировать текст, чтобы пользователь мог изменить текст, если захотите. Я уже добавил удалитель для удаления, используя приведенный ниже код, однако добавить текстовую функцию редактирования не так просто, чтобы найти информацию, поэтому мой вопрос: как добавить кнопку, чтобы пользователь мог редактировать текст с помощью функция прокрутки? мне нужно знать код, чтобы загрузить текст, как я не могу иметь текстовое поле, так что это не так просто, как что-то вроде label.text = textfield.text код, который загружает исходные текст следующим образомКак прокрутить для редактирования текста в таблицеView?

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) 

     cell.textLabel?.text = places[indexPath.row]["name"] 

Спасибо!

override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) { 

     if editingStyle == UITableViewCellEditingStyle.Delete { 

      places.removeAtIndex(indexPath.row) 

      NSUserDefaults.standardUserDefaults().setObject(places, forKey: "places") 

      tableView.reloadData() 

     } 
      } 

ответ

1
func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? { 

    var editAction = UITableViewRowAction(style: .Normal, title: "Edit") { (action, indexPath) in 
       tableView.editing = false 

    // your action 
      } 

      editAction.backgroundColor = UIColor.grayColor() 


    var deleteAction = UITableViewRowAction(style: .Default, title: "Delete") { (action, indexPath) in 
       tableView.editing = false 
    // your delete action 
    } 

    return [deleteAction, editAction] 
+0

Спасибо, беда это действие, чтобы дать редактировать ячейки. Я изначально иметь текст по умолчанию кодируется, как показано ниже, если это поможет: переопределение функ Tableview (Tableview: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { пусть клетка = tableView.dequeueReusableCellWithIdentifier ("Cell", forIndexPath: indexPath) cell.textLabel ? .text = places [indexPath.row] ["name"] –

Смежные вопросы