|
|
#1 |
|
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 |
|
|
|
0
|
|
|
#2 | |
|
Quote:
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 |
||
|
|
0
|
|
|
#3 | |
|
Quote:
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 |
||
|
|
0
|
|
|
#4 |
|
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 |
|
|
|
0
|
|
|
#5 | |
|
Quote:
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. |
||
|
|
0
|
|
|
#6 | |
|
Quote:
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 |
||
|
|
0
|
|
|
#7 | |
|
Quote:
Code:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(getTheFirstResponder:) name:NSApplicationDidUpdateNotification object:nil]; id)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'' Early 2011 MBP | iPhone 5 | iPad (2012) | MacOS X 10.8.3 |
||
|
|
0
|
|
|
#8 | |
|
Quote:
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. |
||
|
|
0
|
|
|
#9 |
|
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 |
|
|
|
0
|
|
|
#10 |
|
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.
|
|
|
|
0
|
|
|
#11 |
|
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 |
|
|
|
0
|
![]() |
|
«
Previous Thread
|
Next Thread
»
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
All times are GMT -5. The time now is 12:53 PM.








id)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.
Linear Mode
