开发者

Dynamic refresh in a view - xcode 4 / interface builder

开发者 https://www.devze.com 2023-03-08 00:01 出处:网络
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:

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?


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)
0

精彩评论

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