Reputation: 207
I want to delete a coreData object from another view with an if-condition.
So in viewControllerA there's the entity Buy used with the attribute cellName. And viewControllerB contains a tableView and the coreData entity List. When the user deletes a cell in viewControllerB the object of viewControllerA which has cellName (viewControllerA) = name of the deleted cell (viewControllerB) should also be deleted. Maybe someone could help me...
Upvotes: 0
Views: 94
Reputation: 5552
There are probably a couple of options including a custom delegate but a possibility to start would be through notifications
In your viewControllerA you would register for a notification in viewWillAppear or viewDidLoad:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(shouldUpdateDisplay:)
name:@"SHOULD_UPDATE_DISPLAY"
object:nil];
NOTE: in your dealloc method you should remove yourself from observer:
[[NSNotificationCenter defaultCenter] removeObserver:self];
Then implement the method:
- (void) shouldUpdateDisplay:(NSNotification *) notification
{
[_table reloadData]; // do your updates
}
In VCB you would send that notification when an element was deleted and the other view controller should know about it:
[[NSNotificationCenter defaultCenter]
postNotificationName:@"SHOULD_UPDATE_DISPLAY"
object:self];
Upvotes: 1