2017-06-05 29 views
0

我想刪除swift3中單元格上的點擊查看的表格單元格。如何刪除swift3中點擊查看的UITableView部分

下面的函數被稱爲點擊查看和刪除方法用於刪除表格部分。但此解決方案不工作。

func remove(sender: UITapGestureRecognizer) 
     { 
      let indexView = sender.view 
      let index = indexView?.tag 

      self.removeAddresses(position: index!) 
     } 

    func remove(position: Int) 
    { 
     tableView.deleteSections(IndexSet(index: position,with. automatic)) 
     tableView.reloadData() 
    } 
+0

要刪除全部或部分只有一行(小區)?也向我們展示了你的tableView的數據源方法。 –

+0

好的..如果你想刪除一個單元格然後在你點擊方法只是寫爲[yourItemArray removeObjectAtIndex:itemIndex]; [yourTableView deleteRowsAtIndexPaths:@ [indexPathCreated] withRowAnimation:UITableViewRowAnimationAutomatic]; –

+0

添加有問題的數據源方法 – KKRocks

回答

1

試試這個:

func remove(position: Int) 
    { 
     yourDataSourceArray?.removeAtIndex(position) 

     tableView.deleteSections(IndexSet(index: position,with. automatic)) 
     tableView.reloadData() 
    } 
0
  1. 要刪除表格單元格,我建議你可以使用編輯風格

方法:

func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { 

      } 
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { 

}   
func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle { 

     } 
  • 而且我認爲,

    func remove(sender: UITapGestureRecognizer){ 
          let indexView = sender.view 
          let index = indexView?.tag  
          self.removeAddresses(position: index!)   
         } 
    
        func removeAddresses(position: Int){ 
        tableView.beginUpdates() 
        yourDataSourceArray.removeObject(at: position) 
        table.deleteRows(at: [indexPathCreated] , with: .automatic) 
        table.endUpdates() 
        } 
    
  • 相關問題