Key View Loop does not work
Key View Loop does not work
- Subject: Key View Loop does not work
- From: John Nairn <email@hidden>
- Date: Mon, 27 Jun 2005 15:51:53 +0200
I am finding it impossible to programmatically create NSTextFields
and link them within a key view loop for tabbing. It is another of a
series of roadblocks I have found when trying to programmatically
creating controls in Tiger (or just Cocoa). Here is the problem:
My application programmatically creates NSTextField cells as subviews
of the documentView of an NSScrollVIew that fills the window. The
cells are created with code like (except I defined sub class of
NSTextField called EditValueCell and the actual code creates
EditValueCells):
NSTextField *textField=[[NSTextField alloc] initWithFrame:myFrame];
[textField setStringValue:myContents];
[textField setFont:theFont];
[textField setDelegate:self];
[[textField cell] setSendsActionOnEndEditing:YES];
Because of the dynamic views, this window does not calculate the tab
view loop, so I do it myself whenever the text fields change. A
method in my documentView is
// set tab ky loop
- (void)setTabKeyLoop
{
id obj,previousCell=nil;
NSEnumerator *en=[[self subviews] objectEnumerator];
while(obj=[en nextObject])
{ if([obj isMemberOfClass:[EditValueCell class]])
{ if(previousCell)
[previousCell setNextKeyView:obj];
else
[[browser window] setInitialFirstResponder:obj];
previousCell=obj;
}
}
if(previousCell)
[previousCell setNextKeyView:[[browser window]
initialFirstResponder]];
// verify the tab key loop
obj=previousCell=[[browser window] initialFirstResponder];
do
{ NSLog(@"tab loop: %@",[obj stringValue]);
obj=[obj nextKeyView];
} while(obj!=previousCell);
}
The loop at the end is for debugging and loops through the window's
key view loop and verifies that it is set exactly as expected for all
my EditValueCell classes (subclass of NSTextField)
Nevertheless, tabbing does not work. Tabbing in an editing text field
selects that text field on the first tab and then selects the first
responder on the second tab. It never goes through the key view loop
when tabbing.
---------------
John Nairn (1-801-581-3413, FAX:1-801-581-4816)
Web Page: http://www.mse.utah.edu/~nairn
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden