Text field in Xcode


(Jonas Whale) #1

I have made a tiny app in Xcode with a unique text field.
Is it possible to send its action continuously?
(I mean like the Safari URL field does…)

(Shane Stanley) #2

In the Attributes inspector, click on the Continuous checkbox (in the section labelled State). And make sure your handler can deal with rapid repeat calling.

(Jonas Whale) #3

The continuous attribute is already set.
The script takes 0,000493 seconds to make its calculation and after that sets the content of a label and changes the source image of a little dot (e.g. NSImageNameStatusAvailable).

It does not work: the action is sent only at end editing.

(Shane Stanley) #4

OK, it looks like that only affects bindings.

Make your app delegate the delegate of the text field. Then add a handler like this to the app delegate:

on controlTextDidChange:notif
-- do stuff
end controlTextDidChange:

(Shane Stanley) #5

And if you need to do it for more than one field:

on controlTextDidChange:notif
   set theField to notif's |object|()
   if theField's isEqualTo:firstField then
-- do stuff
end controlTextDidChange:

(Jonas Whale) #6

You mean if I use bindings instead of IBOutlets, there’s no need for the delegate and the controlTextDidChange: handler?

(Shane Stanley) #7

I believe so. I’m still not sure why it’s not working now, though.

(Jonas Whale) #8

That’s it!
It works flawlessly!