NSCollectionView and key view loop
NSCollectionView and key view loop
- Subject: NSCollectionView and key view loop
- From: Martin Hewitson <email@hidden>
- Date: Sun, 10 Mar 2013 14:16:44 +0100
Dear list,
I've been struggling with this for hours and I think it really shouldn't be this hard, so I thought I'd post the problem.
I have an app that contains an NSCollectionView. Each item in the collection view has three text fields. I have finally managed to get the first textfield to be set first responder when a new item is added by doing this in my NSCollectionViewItem subclass:
- (void)setRepresentedObject:(id)object
{
[super setRepresentedObject:object];
[self setFirstResponder];
}
- (void) setFirstResponder
{
MyView *myView = (MyView *)[self view];
NSWindow *window = [[NSApplication sharedApplication] mainWindow];
[window performSelector:@selector(makeFirstResponder:) withObject: MyView.textField1 afterDelay:0.2];
}
-(id)copyWithZone:(NSZone *)zone
{
CollectionViewItem *result = [super copyWithZone:zone];
MyView *view = (MyView*)result.view;
view.textField1 = [view viewWithTag:100];
view.textField2 = [view viewWithTag:200];
view.textField3 = [view viewWithTag:300];
[view setNextKeyView: view.textField1];
[view.textField1 setNextKeyView: view.textField2];
[view.textField2 setNextKeyView: view.textField3];
[view.textField3 setNextKeyView: view.textField1];
return result;
}
My problem is that the tabbing between the three text fields doesn't work. Instead if I tab from the textfield1 of the new item, focus jumps to a button on that item, then from there to textfield1 of the first item in the collection view, from whence it jumps between textfield1 and the button on the first item. Most strange.
Is there a correct pattern to handle this? The code above feels like such an ugly hack. I need the delayed performSelector to ensure the text fields are properly initialized before making them first responder. And apart from that, the tabbing between textfields fails.
Many thanks for any clues,
Martin
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden