views:

41

answers:

1

I need to be able to make a token field with draggable elements like the Mac clock format panel (see the following image).

Thanks so much, Alex.

Token Field

+4  A: 

They're called token fields. Apple has a guide for them. (Without knowing any more details of your goals, that's about as precise as I can get.)

Edit

I noticed the edits to your question. You want something that behaves like System Preference's date panel. Here's a breakdown of what I imagine is happening:

  • In the "Time Elements* section, there are objects (models) that implement the pieces of data you can use in the text field (hours, minutes, seconds, etc.).
  • There is also an associated view for drawing these elements in the same style as the token (maybe taken from something in Cocoa, maybe a custom view).
  • NSTokenField objects can accept arbitrary objects, as well as strings. So you can drag these objects from the "Time Elements" section onto the token field. The token field's delegate than handles these non-string objects.

The guide linked above contains the information for handling non-string elements in token fields. I imagine all you need to do is create models for the data parts you want to represent, and then render them using a (possibly custom) view.

mipadi
I know what a token field is, but how can I make the draggable things like (09) and you can drag it to the token field, and I fill in values for it. How do I do that?
Alexsander Akers
It sounds like you want the section of the guide on represented objects, which explains how to configure tokens used in token fields: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/TokenField_Guide/ReturnRepObjects/ReturnRepObjects.html#//apple_ref/doc/uid/TP40006555-CH8-SW3
mipadi
See my comment above.
Alexsander Akers
How do I "create models for the data parts"?
Alexsander Akers
Same way you'd create any other model. You probably just need one model, maybe with an enum or other identifier telling what type of data it represents; or you could have a model for each piece of data (for instance, a model for hours, minutes, time zone, etc.). That's the represented object you'd be dragging on to the token field, essentially. Then, the token field's delegate could handle all the appropriate methods for providing feedback to the token field. That's one way of architecting it, at least.
mipadi
How would I create a model period?
Alexsander Akers
A model is just a class (it's the "M" in MVC) so you'd just create a class (probably one that extends `NSObject`).
mipadi