2017-12-31 16 views
1

を動作しません。私のシンプルなリストアプリ。私は私が私のテーブルビューセルをスワイプするとき、私はこのSwipeCellKitは、私は今のstackoverflowから画像をアップロードすることはできませんなぜ私は知らないので、私は私の問題</p> <p>を表示するために外部リンクを使用していた場合、私は私がSwipeCellKitを実装しようとしています申し訳ありませんが、正しく

https://raw.githubusercontent.com/jerkoch/SwipeCellKit/develop/Screenshots/Expansion-Destructive.gif

のような偉大なdesctructive効果がありますが、私はコードを実装する場合、それは破壊的なスワイプ効果を持っているdoesntの、でもそれがswippedできないことを期待しますここでは、この

https://ibb.co/mg7w4w

のように削除することがSwipeCellKit

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "toDoItemCell", for: indexPath) as! SwipeTableViewCell 

     cell.delegate = self // for swipe cell 

     if let item = toDoItems?[indexPath.row] { 
      cell.textLabel?.text = item.title 
      cell.accessoryType = (item.isItDone) ? .checkmark : .none 

      // to darken the cell color, 
      let colorFromCategory = UIColor(hexString: (selectedCategory?.color)!) 

      if let color = colorFromCategory?.darken(byPercentage: CGFloat(indexPath.row)/CGFloat(toDoItems!.count)) { 

       // if there is a member in the toDoList Array, 'count' is not nil, then set the background and text color 
       cell.backgroundColor = color 
       cell.textLabel?.textColor = ContrastColorOf(color, returnFlat: false) 
      } 



     } else { 
      cell.textLabel?.text = "You have no items yet" 
     } 


     return cell 
    } 

// MARK: - Swipe Table view Cell Delegate 

extension ToDoListVC : SwipeTableViewCellDelegate { 

    func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath, for orientation: SwipeActionsOrientation) -> [SwipeAction]? { 

     guard orientation == .right else { return nil } 

     let deleteAction = SwipeAction(style: .destructive, title: "Delete") { action, indexPath in 
      // delete selected category from Realm Database 

      // if Categories is not nil then delete the realm database 

      if let deletedItem = self.toDoItems?[indexPath.row] { 

       do { 
        try self.realm.write { 
         self.realm.delete(deletedItem) 
        } 
       } catch { 
        print("error while deleting item from Realm Database: \(error)") 
       } 

       tableView.reloadData() 

      } 
     } 


     // to edit swipe behaviour 
     func tableView(_ tableView: UITableView, editActionsOptionsForRowAt indexPath: IndexPath, for orientation: 
      SwipeActionsOrientation) -> SwipeTableOptions { 
      var options = SwipeTableOptions() 
      options.expansionStyle = .destructive 
      options.transitionStyle = .border 
      return options 
     } 




     // customize the action appearance 
     deleteAction.image = UIImage(named: "delete-icon") 

     return [deleteAction] 



    } 
} 
に関連するコードの実装です

ここに何が間違っていたのですか?

答えて

0

あなたがサンプルアプリケーションを見れば、あなたは(で:.delete):.acction.fullfillを呼び出す必要があります

if let deletedItem = self.toDoItems?[indexPath.row] { 

      do { 
       try self.realm.write { 
        self.realm.delete(deletedItem) 
        action.fulfill(with: .delete) 
       } 
      } catch { 
       print("error while deleting item from Realm Database: \(error)") 
      } 

}

関連する問題

 関連する問題