Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 6, 2013, 02:01 PM   #1
Mark FX
macrumors member
 
Join Date: Nov 2011
keeping track of the urrent first responder

Currently I have a project with an AppController which has the standard MainMenu.xib, with main window and menu bar, I have added a NSViewController class to the project, which controls and displays a custom view class, which is a NSBox subclass, with a xib file that has the NSBox in Inteface Builder.

I have added several TextFields to the box in IB, the app controller gets the view controller to add the box view to the main window, as a subview, that all works as it should, and the text fields all recieve the focus and first responder status as they should with the tab key or mouse click.

My question is, how can I monitor which text field has the focus?

I have IBOutlets to all of the text fields in the NSBox subclass at the moment, and have used the NSResponder keyUp: method to check which text field has first responder status, but the mouse events dont work in the NSBox subclass as the text fields themselves recieve the mouse down and mouse up events, so can not check which text field has been clicked.

I'm sure there is a simple awnser I missing, but How can I check the active text field, when the field is clicked by the mouse, and not tabbed to by the keyboard?

Thanks in advance Mark
Mark FX is offline   0 Reply With Quote
Old Feb 6, 2013, 02:19 PM   #2
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by Mark FX View Post
My question is, how can I monitor which text field has the focus?
...
I'm sure there is a simple awnser I missing, but How can I check the active text field, when the field is clicked by the mouse, and not tabbed to by the keyboard?
What are you trying to accomplish, or what problem are you trying to solve, by doing this?


Text field focus and first-responder status is specifically discussed under "Responder-Related Tasks" in this document:
http://developer.apple.com/library/m...ingBasics.html
chown33 is online now   0 Reply With Quote
Old Feb 6, 2013, 02:27 PM   #3
Mark FX
Thread Starter
macrumors member
 
Join Date: Nov 2011
Quote:
What are you trying to accomplish, or what problem are you trying to solve, by doing this?
As the question implies, I am trying to know the identity of the currently active text field, from many text fields in a custom view.

I could add an NSTextField sublclass to the project, and handle the keyboard or mouse events in this new subclass, but I was trying to find a solution using the NSBox subclass, or its view controller, but cannot find the awnser using these means.

Mark
Mark FX is offline   0 Reply With Quote
Old Feb 6, 2013, 02:39 PM   #4
Sayer
macrumors 6502a
 
Sayer's Avatar
 
Join Date: Jan 2002
Location: Austin, TX
You need your subclass to become a delegate of the text field and implement the control:textShouldBeginEditing: method or do whatever is appropriate.

Are you just trying to make a visual change or control/modify input? It sounds like visual changes. Are there not already sufficieny visual cues as part of the default text field controls or customization options in Interface Builder?
__________________
Obama is a true statesman whose experience as a state senator, half-term US Senator & guest lecturer in a Constitutional Law class has fully prepared him to take control of our nuclear arsenal.-Me
Sayer is offline   0 Reply With Quote
Old Feb 6, 2013, 02:42 PM   #5
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by Mark FX View Post
As the question implies, I am trying to know the identity of the currently active text field, from many text fields in a custom view.
I know that. My question was why does knowing the identity of that text field matter? You believe that knowing this identity is important for some reason, and I'm asking what that reason is.

One can trigger custom actions on specific text fields by giving them a customized editor. There are also delegates that may come into play.

Without knowing what problem you're trying to solve, for which you think knowing the identity of the text field is crucial, we can't really suggest other ways to solve the problem, because we don't know what problem your proposed strategy (knowing the identity of the text field) is trying to solve.
chown33 is online now   0 Reply With Quote
Old Feb 6, 2013, 02:56 PM   #6
Mark FX
Thread Starter
macrumors member
 
Join Date: Nov 2011
Quote:
As originally quoted by chown33
Without knowing what problem you're trying to solve, for which you think knowing the identity of the text field is crucial, we can't really suggest other ways to solve the problem, because we don't know what problem your proposed strategy (knowing the identity of the text field) is trying to solve.
The reason for knowing the identity of the currently active text field is that the user will be able to add predefined custom text formatters to the input, and also the text will be later used in another data form, with its custom formatting being used in this other display.

Yes I have some options for getting the active text field, by subclassing NSTextField, and handeling the mouse and keyboard events in this subclass, and also I can ask the main key window for the current first responder, but I need to know when the text field has been clicked in order to ask the window for this info, But just thought there might be a way that I've missed, for asking the text field's superview, or superviews controller, but I'm starting to think this is'nt possable.

Regards Mark
Mark FX is offline   0 Reply With Quote
Old Feb 6, 2013, 03:52 PM   #7
ElectricSheep
macrumors 6502
 
Join Date: Feb 2004
Location: Wilmington, DE
Send a message via AIM to ElectricSheep
Quote:
Originally Posted by Mark FX View Post
The reason for knowing the identity of the currently active text field is that the user will be able to add predefined custom text formatters to the input, and also the text will be later used in another data form, with its custom formatting being used in this other display.

Yes I have some options for getting the active text field, by subclassing NSTextField, and handeling the mouse and keyboard events in this subclass, and also I can ask the main key window for the current first responder, but I need to know when the text field has been clicked in order to ask the window for this info, But just thought there might be a way that I've missed, for asking the text field's superview, or superviews controller, but I'm starting to think this is'nt possable.

Regards Mark
You have the right idea about asking the key window for its first responder, and you can do it by listening for NSApplicationDidUpdateNotifications.

Code:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getTheFirstResponder:) name:NSApplicationDidUpdateNotification object:nil];
Then just implement - (void)getTheFirstResponderid)sender method to handle the notification. Note that this notification will be sent out after every single event, so its going to get posted often.
__________________
15'' MBP (early 2011) | i7 3770k Hackintosh | i7 Mac Mini (late 2012) | iPhone 5 | iPad 3 (2012) | iPad mini | MacOS X 10.9.2
ElectricSheep is offline   0 Reply With Quote
Old Feb 6, 2013, 03:57 PM   #8
chown33
macrumors 603
 
Join Date: Aug 2009
Quote:
Originally Posted by Mark FX View Post
Yes I have some options for getting the active text field, by subclassing NSTextField, and handeling the mouse and keyboard events in this subclass, and also I can ask the main key window for the current first responder, but I need to know when the text field has been clicked in order to ask the window for this info, But just thought there might be a way that I've missed, for asking the text field's superview, or superviews controller, but I'm starting to think this is'nt possable.
As noted in Sayer's post, see the text-editing delegate methods. The API is in NSControl, not NSTextField. If you didn't see it, it may be because you didn't look in the superclasses of NSTextField.

http://developer.apple.com/library/m...c/cl/NSControl

There is a delegate method for when editing begins, controlTextDidBeginEditing:, and another for when it ends, controlTextDidEndEditing:. There is a third method for any time it changes.

Multiple text fields can have the same delegate object. Refer to the method descriptions in the linked reference to see what is passed in the userInfo dictionary of the notification.
chown33 is online now   0 Reply With Quote
Old Feb 8, 2013, 12:27 PM   #9
Mark FX
Thread Starter
macrumors member
 
Join Date: Nov 2011
Sorry for the slow reply, but thanks to you all for your advice, I'm not going to go for the NSTexFields edit tracking methods, as they are overkill for simply checking the first responder, but I like the idea that ElectricSheep has pointed at with the notification method, Thanks!, but I will check to see how busy that method is with a log statement.

As stated previously I only need to check wether the mouse clicks into the text field, as I already have a way of checking keyboard events for the first responder, with the keyUp method in he textfield's superview.

I think I have grasp of the options now, so again thanks everyone.

Regards Mark
Mark FX is offline   0 Reply With Quote
Old Feb 8, 2013, 03:03 PM   #10
jared_kipe
macrumors 68030
 
jared_kipe's Avatar
 
Join Date: Dec 2003
Location: Seattle
Send a message via AIM to jared_kipe
Haven't done it in Cocoa but in CocoaTouch you can just write a category for UIView that walks through the view hierarchy until it finds the first responder, then returns it.
jared_kipe is offline   0 Reply With Quote
Old Feb 8, 2013, 03:36 PM   #11
Mark FX
Thread Starter
macrumors member
 
Join Date: Nov 2011
Thanks Jared Kipe that might me worth looking into, if it can be done for iOS, I'm sure it could be achieved in an OSX project.

Regards Mark
Mark FX is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
How to schedule auto responder emails Designking Mac Applications and Mac App Store 0 Oct 13, 2013 08:15 AM
Auto responder kevo1011 iOS 7 0 Jun 11, 2013 04:13 PM
Good app for keeping track of grades? (student) MasterHowl Mac Applications and Mac App Store 7 Jan 14, 2013 12:41 PM
Keeping track of edited images in iPhoto ozaz Mac Applications and Mac App Store 0 Jan 13, 2013 07:47 AM

Forum Jump

All times are GMT -5. The time now is 12:52 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC