Re: NSTextField sendActionOn:
Re: NSTextField sendActionOn:
- Subject: Re: NSTextField sendActionOn:
- From: Brad Stone <email@hidden>
- Date: Sun, 17 Jan 2010 14:25:44 -0500
I finally had a breakthrough! I'm not sure it's the "best" solution but it works and hopefully will be instructive for others trying to do the same thing connection views. There's a lot of steps (which is why I think it may not be the "best") so I'll try to be as clear as possible.
1) when a user clicks their mouse in my subclasses NSTextField I send this action:
BOOL theResult = [NSApp sendAction:@selector(notifyViewOfMouseDown) to:nil from:nil];
2) my subclassed view has a method that executes when this action is sent:
- (void)notifyViewOfMouseDown {
NSDictionary *d = [NSDictionary dictionaryWithObject:self forKey:@"view"];
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc postNotificationName:SRVIsSelectedChanged object:self userInfo:d];
}
This allows me to package up the view and send it along in a notification. Packaging the view is **key** here because this is the view that needs to be selected. My subclassed NSCollectionView is registered as an observer of this notification. When it receives this notification I execute this code to update the array controller with a new selectedObject
- (void)handleViewSelections:(NSNotification *)note {
View *v = [[note userInfo] objectForKey:@"view"];
int limit = [[self content] count];
for (int i = 0; i < limit; i++) {
NSCollectionViewItem *item = [self itemAtIndex:i];
View *thisView = [item view];
if ([thisView isEqual:v]) {
[item setSelected:YES]; //my subclassed NSCollectionViewItem knows how to set itself as selected and update the array controller
}
}
}
Boy, I'm glad I figured that out! I'm sure there are a lot more experienced programmers than me out there so if anyone can think of a way I can do this without so many steps I'd be glad to learn from them.
Jonathan, thanks for your suggestion. My subclassed NSTextField didn't respond to superview. I wish it did, it would have saved me a step. To adapt your solution I'd need to register each newly created view in my NSCollectionView link that back to the NSCollectionViewItem that has the code to set itself as selected and to update the array controller. I had to delete your reply from this message to make it thru the listserve size limit._______________________________________________
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