Re: Basics of Cocoa Bindings
Re: Basics of Cocoa Bindings
- Subject: Re: Basics of Cocoa Bindings
- From: email@hidden
- Date: Sat, 12 Sep 2015 21:59:31 +0900
You would implement the NSTableView data source and delegate methods in a class. In a simple case in the app delegate to try them out and get used to them.
Sent from my iPhone
> On Sep 12, 2015, at 9:28 PM, Alex Hall <email@hidden> wrote:
>
> IT! WORKS! Thanks so much for your help. Now I'll advance this project, to test more aspects of this binding, and hopefully grasp things more completely with practical examples I make.
>
> Out of curiosity, you said you never use table view bindings anymore. If you had to display the contents of an array or dictionary in a table, what would you use instead?
>> On Sep 12, 2015, at 00:05, Quincey Morris <email@hidden> wrote:
>>
>> On Sep 11, 2015, at 20:20 , Alex Hall <email@hidden <mailto:email@hidden>> wrote:
>>>
>>> Okay, the error I'm seeing (about [ViewController count]) is the table asking for how big it should be.
>>
>> Actually, that’s not it, though you can be excused for thinking so.
>>
>> What’s wrong is that you tried to add way too many bindings, in particular to the array controller. The only binding needed is the content binding. The managedObjectContext binding must NOT be used, because this is not a Core Data data model (but it probably makes no difference because it’s referencing nil and so I expect the array controller just ignores it). The selectionIndexes and sortDescriptors CANNOT be used in the project as it stands, because your view controller does not have any corresponding properties to bind to. The ‘count’ here is asking for the models’ opinion of the number of selected rows, or the number of sort descriptors. It’s not easy to tell which. In order to use these bindings, the view controller would have to have properties with names that match the model keys. Remember that the model key is just a string. It can’t cause any properties or methods to exist ― you have to do that part.
>>
>> After fixing that, your app crashes with a different error, which is a kind of success because things got a lot further!
>>
>> The later crash was because you bound the wrong thing (that is, the wrong “from” object) when trying to get hold of displayText. In the IB object hierarchy, you bound the thing called “Text Cell”, which is actually a prototype NSCell used for the column header. Normally you just treat is as part of IB’s implementation details and don’t modify it directly.
>>
>> There’s a sub-hierarchy of 3 other things, called “Table Cell View” (which is a NSTableCellView, and it’s the prototype of the top level view for each cell), "Table View Cell” (which is your text field), and “Table View Cell” (yes, the same name, which is the NSCell that the NSTextField machinery uses and you similarly ignore in IB, in most cases).
>>
>> So after deleting the incorrect “Text Cell” binding, your project runs, although the rows don’t show anything because the text field isn’t actually (wasn’t ever) bound to anything.
>>
>> To complete this example ― to get the text from Tweet.displayText to be shown in the table ― you have to hook up the the text field (the one called “Table Cell View”, but not the NSCell of that name) via binding or whatever so that it resolves its value through the Table Cell View’s objectValue. That’s the “advanced” part, and I don’t remember exactly what to do because I never use table view content bindings any more. If you carefully follow through the example of table content bindings the table view programming guide, you should be able to figure this out, but you’re on your own. I don’t feel obliged to make your self-inflicted pain my self-inflicted pain. :)
>>
>>> That makes way more sense--I was under the impression that the array controller was asking on the table's behalf, that's why I expected it to use countOfTweets().
>>
>> As it turned out, the array controller wasn’t asking about the tweets at all. But if it was, it would use “count" because it’s an *array* controller, and the standard behavior that returns the count is “count”. Note that the table view doesn’t even know the name of the relevant property, because it’s hidden on the “other” side of the array controller, not to mention buried inside a binding. It’s “count” all the way down the line.
>
>
> --
> Have a great day,
> Alex Hall
> email@hidden
>
> _______________________________________________
>
> 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
_______________________________________________
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