Reputation: 161
I am having problems updating the content of two tables, which are placed in two different tabs of a NSTabView
and each controlled by a different controller (Controller1 and Controller3), from a third controller (Controller2).
I tried three different approaches:
Approach #1:
I created in Controller1 (the controller of the table invitesTableView
) the method refreshTable :
- (void)refreshTable {
invites = //fill my mutable array
NSLog(@"%@",invites);
[self.invitesTableView reloadData];
NSLog(@"invite's table view updated");
}
which I later call from Controller2 doing :
Controller1 *controller1 = [[Controller1 alloc] init];
[controller1 refreshTable];
NSLog
prints the content of the array invites correctly, but the table is not updated. I should say that, at application launch, I call the very same method in Controller1 and the content of the array invites is correctly loaded in the table.
Approach #2: When in Controller2 I do:
Controller1 *controller1 = [[Controller1 alloc] init];
controller1.invites = //fill my mutable array
NSLog(@"%@",controller1.invites);
[controller1.invitesTableView reloadData];
But again the content of the table is not updated, even if the NSLog
shows the correct content.
Approach #3: As Controller1 controls the content of a NSTabViewItem
, I integrated in Controller1 the method:
- (void)tabView:(NSTabView *)tabView didSelectTabViewItem:(NSTabViewItem *)inviteTab
and it works just fine, because I call the method refreshTable
as soon as open the tab controlled by Controller1. The problem is that I have different tables in different tabs but I can set only one controller as the delegate of the NSTabView
, so I can not update the table controlled by Controller3 in a different table.
I don't think there is an easy solution to approach #3, apart from merging Controller1 and Controller3, but I think I am just missing something with respect to the first two approaches.
Hope I explained myself clearly. Can anyone help? Thanks in advance!
Upvotes: 1
Views: 788
Reputation: 46543
You can use notifications/observer to reload tableview.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(reloadTable:)
name:@"reloadNotification"
object:nil];
- (void)reloadTable:(NSNotification *)notif {
[self.tableName reloadData];
}
In your first tab use this:
[[NSNotificationCenter defaultCenter] postNotificationName:@"reloadNotification"
object:nil];
Upvotes: 3