tags:

views:

314

answers:

3

I write custom jabber client in iphone.

I use xmppframework as engine.

And I have UITableViewController with NSMutableArray for repesent contact list.

When i receive(or somebody change it contents) roster (aka contact list) i wanna change UITableView items (add/remove/modify). So if User work with listView at time when list updates by

[items addObject:newItem];
[self.tableView reloadData];

user lost current selection item.

So, my question is howto save (if possible, i mean if given selected item not removed) current select item after reloadData?

Thx.

A: 

It sounds like you are not using a 'model' for the data - rather simply updating the 'view' (user interface), and thus is probably a bad design.

reloadData should cause the view to be updated with data from the model, which should contain the most current data to be displayed.

search for resources on the 'model view controller pattern'

Mobs
no, I really use NSMuttableArray for delegate Table Data Source and add/remove data in this array, but to make refresh tableView I call reloadData method after modifying array. Am I right? But after this tableView lost selection.
vinnitu
Its hard to help you without seeing your code, but the tableView's methods should create the table from the data source, thus you simply update the data model and fire reloadData.
Mobs
+1  A: 

The workaround is to use reloadSections: instead of reloadData. For some reason reloadData removes the current selection.

Greg
A: 

The easy way is something like this:

NSIndexPath *ipath = [self.tableView indexPathForSelectedRow];
[self.tableView reloadData];
[self.tableView selectRowAtIndexPath:ipath animated:NO scrollPosition:UITableViewScrollPositionNone];
Marco