[MacRuby-devel] Dynamic refresh in a view - xcode 4 / MacRuby

Laurent Sansonetti laurent.sansonetti at gmail.com
Tue May 24 20:01:55 PDT 2011


Hi,

It doesn't work because you're (probably) blocking the main thread,
which is responsible for drawing. What you want to do instead is
scheduling a timer inside the main run loop. Look at the NSTimer
class. Also, don't forget to force the view to be redrawn, by using
the setNeedsDisplay: method.

HTH
Laurent

On Tue, May 24, 2011 at 5:06 PM, azzzz at gmx.net <azzzz at gmx.net> wrote:
> I have a label that I have set to blank, and after a user clicks 'go' I generate a random word or number and use:
>
> self.label.stringValue = "some_word"
>
> to update the view.
>
> However, I would like to show 200 or so random words in quick succession before the final one is shown - just because it's too plain at the moment. Alternatively, I'd be happy with showing an animated graphic in its place - which is replaced by the final random word after a few seconds.
>
> I've tried things like:
>
> 100.times do
>  num = rand(40)
>  self.label.stringValue = num
>  sleep 1
> end
>
> But it doesn't work. I've also (after googling) tried .reloadData but to no avail as well.
>
> Any ideas on how to achieve this? Or pointers on how to add animations to my window/views?
> _______________________________________________
> MacRuby-devel mailing list
> MacRuby-devel at lists.macosforge.org
> http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel
>


More information about the MacRuby-devel mailing list