Re: another question about view based NSTableViews
Re: another question about view based NSTableViews
- Subject: Re: another question about view based NSTableViews
- From: Ken Thomases <email@hidden>
- Date: Sun, 15 Mar 2015 20:35:04 -0500
On Mar 15, 2015, at 8:24 PM, Patrick J. Collins <email@hidden> wrote:
> So, I have my NSTableView which is made up of NSTextFields as cells...
> How do I handle knowing when the value of one of these text fields
> change?
>
> The docs say that with a view based table, the subviews (i.e. columns)
> should handle their own behavior, but-- how does a NSTextField (my cell
> view) know what row it's in, what column it is, etc... ?
There are several approaches. One simple approach is to configure the target and action for the text fields, so they invoke an action method on a controller when editing completes.
In the action method, the controller finds the row using [tableView rowForView:sender]. It can also find the column using [tableView columnForView:sender], but that's a column index and that's not enough. You then have to use that to index into the table's tableColumns array to get an NSTableColumn and then ask that for its identifier. (The reason that a column index isn't enough is that columns can be re-ordered or hidden. Also, as your design changes, you may add or remove columns.) Alternatively, if the columns are semantically different, then the text fields in each column could use a different action method and each action method would implicitly know which column it's for.
Regards,
Ken
_______________________________________________
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