When changing my model, I want to animate the changes in the UITableView by inserting / deleting rows. To do this, I need to know the sequence number of this string (so that I can build NSIndexPath), which I find difficult in more than linear time.
For example, note that I have a list of entries in the address book that are manually sorted by the user, i.e. There is no order key that represents the sort order. There is also a corresponding UITableView that shows one row per entry in the address book. When a UITableView requests a data source, I request an NSMUtableArray populated with my records and return the necessary data at constant time for each row.
However, if there is a change in the base model, I get a notification "Joe Smith, id # 123 has been deleted." Now I have a dilemma. A naive approach would be to scan the array, determine the index in which Joe Smith is located, and then ask the UITableView to remove this exact row from the view and also remove it from the array. However, scanning will take linear time.
Now I can have an NSDictionary that allows me to find Joe Smith in constant time, but that doesn’t do me much good, because I still need to find his ordinal in the array to instruct the UITableView to delete this row, which again is a linear search . I could also decide to keep every object ordinal inside the object itself to make it permanent, but it will become obsolete after the first such update, since all subsequent index values will be changed due to the removal of the object.
So, what is the correct design pattern to accurately reflect model changes in a UITableView in a costant (or at least logarithmic) state?
source
share