Corey Floyd
Corey Floyd

Reputation: 25969

What does the UITableView method "deleteRowsAtIndexPaths: withRowAnimation:" do?

********Update to Question**********

If the tableview does not affect the model: 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?

*******Original Question**********

I know it marks the cells for deletion and animates the deletion, but what does it do to the model?

Does it affect the model at all (I can't imagine it does)?

Are the cells "still there" but invisible?

When the user begins to scroll does it skip delegate calls for the deleted indexes?

Does it expect you to update the model?

Seems vague from what I have read so far...

Upvotes: 1

Views: 5486

Answers (2)

Jordan
Jordan

Reputation: 21760

  • (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.

Upvotes: 5

Rog
Rog

Reputation: 17170

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...)

Upvotes: 1

Related Questions