Advertisement
Guest User

Untitled

a guest
Sep 19th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 2.13 KB | None | 0 0
  1. override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  2.         // #warning Incomplete implementation, return the number of rows
  3.         return chapters.count
  4.     }
  5.  
  6.    
  7.     override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  8.         let cell = tableView.dequeueReusableCell(withIdentifier: "reuse", for: indexPath)
  9.        
  10.         return chapters[indexPath.row].asTableCell(cell)
  11.     }
  12.  
  13.     override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
  14.         // Return false if you do not want the specified item to be editable.
  15.         return true
  16.     }
  17.    
  18.     /*
  19.     override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {
  20.         if editingStyle == .delete {
  21.             _ = chapters.remove(at: indexPath.row)
  22.             tableView.deleteRows(at: [indexPath], with: .fade)
  23.         } else if editingStyle == .insert {
  24.             // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
  25.         }
  26.     }*/
  27.    
  28.     override func tableView(_ tableView: UITableView, performAction action: Selector, forRowAt indexPath: IndexPath, withSender sender: Any?) {
  29.        
  30.     }
  31.    
  32.     override func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
  33.        
  34.         let delete = UITableViewRowAction(style: .destructive, title: "Delete") { (action, indexPath) in
  35.             // delete item at indexPath
  36.             self.chapters.remove(at: indexPath.row)
  37.             tableView.deleteRows(at: [indexPath], with: .fade)
  38.         }
  39.        
  40.         let share = UITableViewRowAction(style: .normal, title: "Share") { (action, indexPath) in
  41.             // share item at indexPath
  42.             print("I want to share: \(self.chapters[indexPath.row].title)")
  43.         }
  44.        
  45.         share.backgroundColor = UIColor.lightGray
  46.         share.backgroundEffect = UIVisualEffect()
  47.         return [delete, share]
  48.        
  49.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement