Swift - Tableview delete / remove row tutorial

preview_player
Показать описание
Tutorial on doing deleting a UITableview Row in Swift.

Рекомендации по теме
Комментарии
Автор

To add to what he has, if you're deleting information from Core Data as well as the tableview, the code looks like this:

func tableView(tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool {
        return true
 }
    
 func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
        if(editingStyle == {
            let appDelegate =
as! AppDelegate
            
            let managedContext =
            
            do{
// substitute the "people" with the name of your [NSManagedObject]

                try managedContext.save()
            } catch let error as NSError {
                print ("Couldn't delete. ERROR: \(error)")
            }

        }
    }

trevornestman
Автор

What is tableData? is it an array of some sort ? I tried to find your source code but could not locate it on github

blazebladde
Автор

Thanks for this! Your videos are great!

I am trying to combine this delete function with the reordering of rows and for some reason have not been able to make it work. Would this code somehow clash with the code that reorders rows? I am new to Xcode, so thank you for your patience.

I used your tutorial for reordering, which is working perfectly. I can build the deleting row out by itself, but have not been able to figure out putting those together.



I've tried putting in one piece of code at a time to see what exactly is stopping the "delete" function from working. I believe this is it:

func tableView(tableView: UITableView, editingStyleForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCellEditingStyle {
return
}

joshuazonker
welcome to shbcf.ru