Re: NSTextField sendActionOn:
Re: NSTextField sendActionOn:
- Subject: Re: NSTextField sendActionOn:
- From: Brad Stone <email@hidden>
- Date: Sun, 17 Jan 2010 11:30:45 -0500
Here's why I need this - I've been trying to solve this problem for 2 weeks!
This issue all revolves around a NSCollectionView. Each CollectionViewItem has a view containing a NSTextField, NSDatePicker, NSButton (checkbox), and an NSLevelIndicator. The selection index of my CollectionView is binded to the selection index of an NSArrayController. The problem I having is if the user performs a mouseDown in the TextField I need to update the selectionIndex of the array controller so the CollectionView will show the appropriate view as selected. Without this, the wrong view is selected. Here's a quick example:
1) click the add button twice to create two items in my collectionView. Items with index 0 and 1. Since item 1 was the last one created, it is selected (I have it showing a grey box).
2) click your mouse into the text field of the item at index 0 and start typing
The user would expect item 0 to be the selected item but it's not. The array controller still thinks item 1 is selected. It needs to be told otherwise. If the user pressed the remove button item 1 would be removed.
This is why I want to fire an action when the user inserts into the text field (just like I do when the user clicks the checkbox). I want to change the selectedObject in the array controller. The problem I'm having with subclassing the NSTextField is I can't figure out how to get the CollectionViewItem from the subclassed TextField. If I could I could then execute my method to update the ArrayController. I tried creating an IBOutlet to the CollectionView, the ArrayController and the CollectionViewItem but they all come back as nil. I think I read here that IBOutlets don't work in this instance. I also tried setting up my own Notification but the CollectionViewItem never receives it (other objects do).
This is tricky, any help you may have would be appreciated.
Brad
On Jan 17, 2010, at 6:12 AM, Graham Cox wrote:
>
> On 17/01/2010, at 3:56 PM, Brad Stone wrote:
>
>> I was able to capture the mouseDown event in the field but only in a subclass which is causing me problems elsewhere.
>
>
> Indeed, a mouse click is not the only reason a field might become focused - the user could tab into it as well.
>
> Overriding -becomeFirstResponder should do it.
>
> Taking a step back though, WHY do you need to get notified here? What are you trying to do? There might be a better way.
>
> --Graham
>
>
>
>
_______________________________________________
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