I'm using a SplitViewController. In MasterViewController's viewDidLoad:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reloadMasterTable:) name:ReloadMasterTableNotification object:_detailViewController];
In DetailViewController, I have two text fields. On didEndEditing:
- (void)textFieldDidEndEditing:(UITextField *)textField {
if ([_detailItem isKindOfClass:[Pill class]]) {
Pill *p = (Pill *)_detailItem;
if (textField.tag == TEXTFIELD_NAME_TAG) {
p.name = textField.text;
}
if (textField.tag == TEXTFIELD_NOTE_TAG) {
p.note = textField.text;
}
[self updateMasterTableView];
}
}
- (void)updateMasterTableView {
if ([_detailItem isKindOfClass:[Pill class]]) {
Pill *currentPill = (Pill *)_detailItem;
NSUInteger indexToReplace = [[[DataManager sharedInstance] pillArray] indexOfObject:currentPill];
[[[DataManager sharedInstance] pillArray] replaceObjectAtIndex:indexToReplace withObject:currentPill];
NSLog(@"i should update row: %i", indexToReplace);
NSIndexPath *path = [NSIndexPath indexPathForRow:indexToReplace inSection:0];
NSDictionary *dict = [[NSDictionary alloc] initWithObjectsAndKeys:path, @"IndexPath", nil];
[[NSNotificationCenter defaultCenter] postNotificationName:ReloadMasterTableNotification object:self userInfo:dict];
}
}
From the NSLog, when the text field delegate method gets called, it only gets called once, and then updateMasterTableView gets called once. When I run it through the debugger, putting a break point on the reloadMasterTableView: method, it goes through the method twice. Why is that? Thanks.
Or if there is a better way to synchronize between the two views, I'm all ears.