views:

90

answers:

1

Hello. I am a student programmer who has taken up Objective-C on my free time as my college doesn't teach it. We have only used Java and basic C so far. I am in the middle of making a program for the iPod and was wondering if there was any type of way to call a method in a class similar to the way a Focus Listener does in Java? I have a view that I would like to call a refresh method (to update the newly inputted titles of buttons from another view) when the view is put at the top and visible again. Is this too easy or is there a more methodical way of doing that? I have tried to just call the method from the other view class but it does not seem to work (says the other class is either undefined or may not accept the method call and crashes on execution).

Any insight would be appreciated. Thank you for your time.

+1  A: 

Hi,

I don't know if I have understood the issue very well but when a view is being visible the "viewDidAppear:" method is call in the UIViewController.

Otherwise the equivalent of the Listener pattern in Objective-C is the NSNotification. You can add an Observer like that:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(aMethod) name:@"aNotification" object:nil];

And the Observed handled his message like that:

[[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:@"aNotification" object:nil]];
Yannick L.