Delete / move UITableView string attached to web service

Removing or moving rows for a UITableView supported by local data (e.g. NSArray) is easy and instant:

  • Remove value from array.
  • Challenge deleteRowsAtIndexPaths:withRowAnimation:.
  • Profit!

But my view of the table interacts with the web service, which means that after clicking the "Delete" button on this line I need to send a request to the server (via ASIHTTPRequest , of course), get a response, and then tell the table view to start a little animation with deletion , all with a gap of a few seconds between them.

From a high level, what is the best way to do this? Throw multiple callback selectors in the ASIHTTPRequest userInfo dictionary? KVO ?

Bonus points for a nice interface, for example, some kind of counter in a cell that will be deleted soon.

+3
source share
1 answer

The most elegant way I know is to use Core Data for local data and listen to the UITableView for change notifications from the Core Data repository. This supports model / view separation, and yet you can still get a glamorous animation of the string animation. This happens as follows:

  • The user says to delete the line.
  • ASIHTTPRequest , , .
  • , , .
  • UITableView , , .

, , . , , , , - , , - , , ASIHTTPRequest /; , , . , , , - . Core Data "" , , , .

Core Data, KVO - .

: , , , Core Data , "ForDeletion" -; ASIHTTPRequest, , markForDeletion true. UITableView ( ); , , . - , , . , ASIHTTPRequest , ; , " " false, UITableView .

+3

Source: https://habr.com/ru/post/1780579/


All Articles