In objective-c (xcode), how to know a view's focus changed

Go To StackoverFlow.com

0

I am new to objective-c (Xcode) program.

I would like to know how to get event when a view's focus gettting and losing focus.

The view is not disposed. Just there is another subView added to the window.

        [self.window addSubview:anotherView.view]

So there will not be viewWillDisappear, viewDidDisappear, viewWillAppear, viewDidAppear for the original load view... :(

Thank you very much.

2012-04-05 02:07
by Johnny
This is dependent on whether it is iPhone or OS X, and it is also dependent on the type of view. A plain view will not receive focus, but a textfield will. Read up on the responder chain to learn more about this - sosborn 2012-04-05 02:26
The term focus usually relates to the current first responder, i.e. the first object in the current responder chain. It doesn't sound like that's what you're asking about, though. Could you edit your question to better explain what you're trying to accomplish - Caleb 2012-04-05 02:42
What I want to do is to show view "A" and keep on doing something by running a timer in that view. Then another view "B" covers on view "A". And stop the timer of view "A". When view "B" disappears, reactivate the timer of view "A" timer - Johnny 2012-04-05 03:11
Yeah, that is a very different question - sosborn 2012-04-05 05:08
Hmmmm... Maybe I should make my question simple... What are the notifications that inform a view becoming visible/invisible - Johnny 2012-04-05 07:47


0

You don't really need one, because you are controlling the adding and removal of the views. However, you can override - (void)didAddSubview:(UIView *)subview in your view subclass (UIView or NSView).

According to the docs:

The default implementation of this method does nothing. Subclasses can override it to perform additional actions when subviews are added. This method is called in response to adding a subview using any of the relevant view methods.

2012-04-05 11:08
by sosborn
Ads