views:

249

answers:

2

Hi,

I've implemented edit menu from my custom UITableViewCell class. I have a small problem of updating a table view from inside the custom table cell class. What is the best approach to do that?

TIA

Clarification: By edit menu I meant a standard Cut/Copy/Paste... menu, that can complies with a standard UIResponder protocol. I want to cut/copy/paste cells content, which resides in some data structure (kind of folders/files tree). The cell actually only reflects the data.

The menu shows up on tap & hold on table cell. The table is derived from UITableViewController and created on fly (not from the xib). Cut/Copy actions are allowed for folders & files, while Paste action is allowed only for folders. Actually I need to refresh only the folder cell, which shows the number of items inside.

So in my CustomCell in paste selector I do the following:

- (void)paste:(id)sender {
  ... Perform a paste of data...
  MyTableViewController  *myTable = (MyTableViewController  *) delegate;
  [myTable performSelector:@selector(updateData) withObject:nil afterDelay:0.3];
}

In MyTableViewController:

- (void) updateData
{
   [self.tableView reloadData];
}

The thing is that all cells except of the one that was changed are redrawn. I see it in cellForRowAtIndex function. Even if I add in paste selector [self setNeedsDisplay] it doesn't help.

Also, my custom cell overrides setHighlighted function:

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated {
  if (delegate)
    [delegate copyableTableViewCell:self willHighlight:highlighted];
  [super setHighlighted:highlighted animated:animated];
}

so the delegate (MyTableViewController) shows an edit menu there. And again the question is why the changed cell doesn't refresh?

Thanks

A: 

Do you want to update a single cell or the whole tableview? What about some kind of delegates, or selectors?

antihero
It can be a single cell. I tried delegates and selectors. I tried also performSelector afterDelay and it's not being called. What is the best practice?
Nava Carmon
A: 

Resolved. Calling in MyTableViewController:

- (void) updateData
{
   [self.tableView performSelector:@selector(reloadData) withObject:nil afterDelay:0.3];
}

and it does the work...

Nava Carmon