Choosing the order that text fields cycle when tab is pressed - cocoa

I have several text fields and would like to set a particular order in which they would cycle when the tab key is pressed. Currently, it starts at a text field with becomeFirstResponder and then goes on in the default order which xcode put. Can I somehow bypass that order and force the text fields to cycle in a particular order? Like linking the last one of the cycle back to the first one.
Thanks for the help.

Connect the initialFirstResponder outlet of your window to the first text field, then build a chain by connecting the nextKeyView outlet of that text field to the text field that should come next (and so on).

That's called the key view loop.

Related

NSDatePicker nextKeyView

It seems that the NSDatePicker nextKeyView is never taken into account.
I can key tab to the NSDatePicker, but never get out of it though nextKeyView is correctly set.
When inside the picker, if I press the tab key, the focus goes correctly from day to month to year text fields, but is sticked in year text field and does never go to the nextKeyView control.
Same thing in the reverse direction, shift-tab goes correctly from year to month to day but is sticked there inside the NSDatePicker.
I guess this is a bug of NSDatePicker.
How can I subclass (or any other type of solution) to overcome this problem ?
Also, a log of the next key view chain, just to prove they are set
Initial first responder <NSTextField: 0x100587c60>
next key view <NSDatePicker: 0x6000035008f0>
next key view <NSComboBox: 0x100636740>
next key view <NSTextField: 0x10063e5a0>
next key view <NSTextField: 0x100587c60>
Here is the catch :
The controller that manages the view has a keyDown: method, because it needs to react on a "delete" key down. This method was not calling [super keyDown:event] if the pressed key was not "delete" (such as the "tab" key).
Adding the call to super when the key is not to be handled by the controller solved the problem.
Why was a tab key pressed handled correctly in some cases (e.g. when focus is on a text field) and not other cases (e.g. date picker) remains unexplained.
Thanks to all the persons that posted comments and help me figure this out.

Filtering text in NSTableView

I have an NSTableView in which I need to be able to intercept keyboard events within an editable cell and replace the cell with strings. For example, press "a" and have the "a" intercepted and the value "Alpha" assigned when the table reloads. The actual situation is a bit more complex in that I'm also handling HID devices, but that's a whole other story. Suffice it to say, I just want to be able to go into edit mode and stop the keyboard-generated values from being displayed.
The latter part of this (displaying "Alpha") is easy, but I can't figure out the first part of the problem. If I subclass the table and make it first responder, I can receive the keyDown: event, but once the user double-clicks on a cell and starts typing, this goes silent.
Since none of the other NSTableView components (NSCell, NSTextFieldCell, etc) derive from NSResponder, I'm assuming there is an NSTextField buried in there somewhere.
So, what's the best way to filter text once the user goes into cell edit mode?
As always happens: after working on this for eight hours, reading all the docs five times, and then resorting to the net, I find the answer five minutes later:
- (BOOL)textShouldBeginEditing:(NSText *)textObject.
Sorry to consume bandwidth.

NSStepper ignores current NSTextField value

I have the same initial problem as described in Integrate NSStepper with NSTextField:
I need to have a NSTextField working with a NSStepper as being one control so that I can edit an integer value either by changing it directly on the text field or using the stepper up/down arrows.
Using bindings as commented on by carlosb results in a usable UI. However, in the initial question carlosb describes the following:
Problem is that if I edit the text field then click the stepper again it will forget about the value I manually edited and use the stepper's internal value.
This is why I am posting a variation on this question again. carlosb's use of bindings doesn't solve this problem. This happens in both the current project I am working on and a test project I have created. The test project can be found at GitHub. You can download it there (even without git) via the "Download Source" button in the top right.
Is there a clean way to solve this issue?
Text fields and sliders are both in the view layer of the MVC pattern. You'll have much better results by binding both of those views to a property of your controller.
Your problem is that that the editing isn't ended until you press return or the field loses focus (so the number is never actually changed). If you press return or leave the field after editing, you'll see it works as expected.
One solution is to check the "Continuously Updates Value" option in the text field's value binding and check the "Continuous" option in the text field's attributes.
This will make sure the value is being updated as it's typed, so an immediate click on the stepper will reflect these changes.

Dynamics AX 2009 Report: LabelPosition above does not work?

I'm just in the process of changing the SalesInvoice Report. One thing I'm trying to do is show the label of some items not left of the item value but above it instead.
Seems easy enough: just change the LabelPosition (for example from CustInvoiceJour_InvoiceId) setting from "left" to "above" and voila: the label has vanished. It is just shown nowhere at all.
Strange. I would have expected the label to show up, well, above the content. Not to vanish.
Am I missing something (there is no label height to set), or is this functionality broken?
I'm not sure if this functionality is broken. But in generated design, these elements will not show the label if it's set to above:
Prolog
PageHeader
Header
Footer
Epilog
ProgrammableSection
If the item you're trying to change is in one of those, then the label position above will, from my experience, not work.
My tip is to create a new control of the text type and then use the same label that the extended data type for the field uses under the "text" property and then adjust the position so it is positioned above the field you're trying to set a label on.
From what I have noticed for a ProgrammableSection the column name labels are not shown only on the first page of the report. The labels are shown on the next pages.

cocoa + what ui element should i use?

I am developing an app which has a text field box. so when i am entering text, it should search the database and give me suggestions just like google search. like if i have entered letter 'a', it should have a box like thing below text field with all names starting with letter 'a'. then if i have entered letter 'b', it should resize the box and give names that start with 'ab' and so on.
I was planning to use a table view below the text field which reloads itself as and when new thing is entered into text field. but i dont know how to resize the table view depending on number of suggestions. So is there any other ui element which suits this kind of situations?
Also how do i detect a new alphabet or number entered into text field so that i can filter out suggestions like is there any such notification? what i mean to say is say i entered letter 'a' so now the string value of text field is 'a' and now i entered say 'b'. so now the string value changed to 'ab'. how do i detect this? i think textDidChange notification will do this for me.
Thanks
You can use an NSComboBox for auto-completing lists like you describe. NSComboBox is a subclass of NSControl so you can use the -controlTextDidChange: delegate method to detect changes in the text that the user types. Make sure you set the control to "continuous" in Interface Builder or call [comboBox setContinuous:YES].
If, for whatever reason, you find that a combo box is inappropriate for your situation, you can implement the list of completions as a child window of the control's window, with a headerless table view in it. Then you would programmatically resize that window as the number of possible completions changes.

Resources