Reputation: 332
I want to remove a table cell on click of view which is on cell in swift3.
Following function is called on click of View and remove method is used to delete table section.But this solution is not working.
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()
}
Upvotes: 0
Views: 1932
Reputation: 4008
Methods:
func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
}
func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? {
}
func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
}
And I think ,
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()
}
Upvotes: 0
Reputation: 8322
Try this :
func remove(position: Int)
{
yourDataSourceArray?.removeAtIndex(position)
tableView.deleteSections(IndexSet(index: position,with. automatic))
tableView.reloadData()
}
Upvotes: 1