oybcs
oybcs

Reputation: 327

Update UITableViewCell from another View

I have a tableview filled with custom cells. In every cell there are two buttons and if I press the first one I navigate to another view, lets call it secondview.

On my secondview there is one button which has the same functionality as the second button on my cell from the previous tableview. When I press the button on my secondview I hide it, but I also want to hide the second button on my cell.

But attention! I only want to hide the second button on this particular cell where I pressed the first button, not all of them!

How can I do that? Thanks in advance!

Upvotes: 0

Views: 382

Answers (3)

Mac
Mac

Reputation: 111

@Cernal, is 'object:fooModel' refering to 'fooModel.xcdatamodeld' or have I missed something?

Upvotes: 0

Cemal Eker
Cemal Eker

Reputation: 1266

Easiest way to implement this is using notifications. On your data model when model changed publish a notification.

[[NSNotificationCenter defaultCenter] postNotificationName:@"fooModelChanged" object:self];

On views and view controllers where you want to listen a model's fooModelChanged notification add this and implement a listener method.

- (void)viewDidLoad {
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fooModelHasChanged:) name:@"fooModelChanged" object:fooModel];
}

- (void)fooModelHasChanged:(NSNotification*)notification {
   // Add buttons, remove buttons or simply...
   [self.tableView reloadData];
}

The problem could be solved with a better approach by using delegates. But it would take longer to explain and implement. I suggest you read more objective-c codes to understand listener implementations.

Upvotes: 1

Templar
Templar

Reputation: 1694

You should pass the first view as a delegate to the second view and when the change is made in the second you will call the first view's hideSecondButton or whatever mwthod you make. Anyway, your problem's keyword is delegate.

Upvotes: 2

Related Questions