Closed jr180180 closed 8 years ago
Yes. That's how it's supposed to work. Basically you need to delete the object from the database with the on_cell_deleted method but return false so the table view doesn't try and delete the cell, the database sends a notification that the table listens to when it's delete. Returning false from that method basically tells the table that it's not allowed to delete the row.
Ahhh, gotcha. I think I understand now.
You're saying I could have written it like:
def on_cell_deleted(cell)
@names.all[cell[:arguments][:id]-1].destroy
cdq.save
false
end
and it would skip this part, right?
unless delete_cell == false
self.promotion_table_data.delete_cell(index_path: index_path)
deletable_index_paths << index_path
end
Looks like when I tried that the first time around, I forgot to return false. Stupid me. :(
You got it. That should work for deleting rows.
Thanks for your help here, @markrickert ! Really appreciate it.
I love how this works so freakin' well!
For others reading this, I originally created an id argument in my model
def cell
{
# Use the model's properties to populate data in the hash
title: name,
subtitle: "Something else: #{something_else} - #{id}",
action: :msg,
editing_style: :delete,
arguments: {id: id}
}
end
and used that for the on_cell_deleted above.
Hence:
@names.all[cell[:arguments][:id]-1].destroy
Turns out, the id argument isn't even necessary. You can pass a second parameter index_path into your on_cell_deleted method and easily remove the row with that. So much easier then trying to make sure you're creating unique IDs for your rows. :)
Here's what you can use instead:
def on_cell_deleted(cell, index_path)
@names.all[index_path.row].destroy
cdq.save
false
end
_High Fives to gem authors_ :hand:
Hope this thread helps someone!
Hey RedPotion team! I'm not sure if this is an issue. Could be an opportunity to enhance RedPotion.
Going through the getting started tutorial, I created a DataTableScreen with a CDQ Model. When I tried deleting a row, it wouldn't allow me to do so using the on_cell_deleted method. I couldn't access the CDQ methods from within that method.
I posted about this in the RubyMotion forum.
Within my controller, I had to use delete_row instead:
If that's actually how it's suppose to work or if you have any advice on this, please let me know. :+1:
Thanks a ton!