0

I'm new to xcode so please bear with me.

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. (I am using MacRuby btw)

However, I would like to show 20 or so random words in quick succession before the last one is shown - just because it's too boring at the moment. (Alternatively, I'd be happy with showing an animated graphic in its place - which is replaced by the final random word.)

I've tried things like:

100.times do
 num = rand(40)
 self.label.stringValue = num
end

But it doesn't work. I've also tried .reloadData but to no avail as well.

Any ideas on how to achieve this?

A4J
  • 879
  • 10
  • 24
  • You can't see it because it's probably happening too fast. Why not just set up a timer with a very small interval that calls a method which iterates through the names you wish to use? – sudo rm -rf May 24 '11 at 22:37
  • I've tried adding 'sleep 1' just to check to see if that works but it doesn't :/ For eg, self.label.stringValue = "Yoooooooo!"; sleep 5; self.label.stringValue = num - is that what you meant? – A4J May 24 '11 at 22:42
  • I'm unfamiliar with MacRuby, so I wouldn't be able to help you any further; I'm sorry. – sudo rm -rf May 24 '11 at 22:43
  • Thanks for trying anyway. Btw, how would you do it in objective-c? (I might be able to port the code) – A4J May 24 '11 at 22:45
  • `[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(myIncrementingMethod:) userInfo:nil repeats:YES];` – sudo rm -rf May 24 '11 at 22:54
  • Thanks (although I wasn't able to port it - objective-c is confusing lol) – A4J May 24 '11 at 23:03

1 Answers1

0

So as not to leave the question haning, from the Macruby mailing list:

def drawWord(sender)
if !next_word
 self.timer.invalidate
 return
end
self.label.stringValue = next_word
self.setNeedsDisplay true
end

def next_word
...
end

self.timer = NSTimer.scheduledTimerWithTimeInterval( 1/20.0,
target:self, selector:"drawWord:", userInfo:nil, repeats:true)
TechZen
  • 64,370
  • 15
  • 118
  • 145