+5  A: 
  • (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;

Deletes a row(s) from the tableView. It does not modify your model at all. You have to do that yourself. The cells are deleted, but if you call reloadData before you delete the row from your Model. The cell will reappear.

So, yes, it expects you to update your model.

Jordan
Are the index path of onscreen cells changed to reflect their actual position OR are the indexes of deleted cells invisible until reloadData is called?
Corey Floyd
You don't need to call -reloadData after using the -insert or -delete methods. Those will update the table view's own row list appropriately. As far as indices are concerned, the table view will be asking YOU what item is at a particular index path, so it's entirely up to you to alter your model so that when the table view requests a new row, you provide the correct one.
Jim Dovey
That makes sense, the delete and insert methods just tell the table to contract or expand. Then you can simply swap out the whole model array if need be
Corey Floyd
+1  A: 

UITableView is a VIEW remember that UIKit is strongly MVC based. It is your responsibility to keep the model updated. Infact, your controller would probably call (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation; in response to observing (or being notified) of a change in your model.

For example, say you UI has a "delete 10 random items". The correct flow for this is:

  1. view - user presses button
  2. controller - receives button press updates model
  3. controller - observes change in model
  4. view updates list

Although it feels a little contrived - why not make the view just update the list and tell the model? it will make bette rcode that is easier to understand and that works better with UIKit. This design for example doesn't assume that the controller in 2 and 3 is the same controller so you have more flexibility.

I would normally apply YAGNI to ll design but I believe the strong MVC focus os UIKit means that YAGNT (you ARE gonna...)

Roger Nolan
This is actually exactly what I have in place. My only point of contention is getting the tableview to animate the transition. just reloading the data does not do this. I have to point out the changes in data to get the animation to happen (as far as I ca tell).
Corey Floyd
If your data is correct then reloadData will work. You should make sure of that in the debugger. You controller can also use `deleteRowsAtIndexPaths` assuming it knows (and it should :-) ) what has been deleted from the model.
Roger Nolan
I am performing a whole sale swap of the model (replacing one array with another). So actually, it doesn't know. I have to through and calculate it what is different between the 2 arrays within the controller and then call "deleteRowsAtIndexPaths". I just thought that was a little excessive, but now I realize that may not be how most people update the model when using the animation functions.
Corey Floyd