开发者

How can I write cocoa bindings as code instead of in the Interface Builder?

In my model I got an NSMutableArray that keeps track of a changing number of elements. In my view I got a NSTextField that shows the number of elements.

The view gets unarchived from the nib file and alloc/inits the modell. Therefore, it knows about the modell and the contained array.

I established the connection as follows. In the Interface Builder at the textf开发者_如何学Cield I added a Cocoa Binding "path" like this: myModell.myArray.@count. By this I can access the count property (which is a must since the array itself does not change).

The binding is based on key-value compliance, which I established at the model so the array can be accessed. But key-value compliance is not part of the questions.

My question: How can I put the binding into the source code and not writing it into Interface Builder?


With the NSKeyValueBindingCreation protocol. You send something like [someObject bind:@"value" toObject:myModel withKeyPath:@"myArray.@count" options:nil].

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜