2010-11-04 74 views
0

我一直在搞乱UILabel代码和NSTimer和WordArray,并且仍然无法弄清楚如何以我需要的方式对它们进行编码。结合基本代码为iPhone工作

我需要每1分钟更换一次UIlabel,但我还需要UILabel更改为100个单词列表中的下一个单词,任何人都可以使用3个单词向我展示此代码的示例或4个字,所以我知道我必须这样做的顺序?谢谢。

UILabel *scoreLabel = [ [UILabel alloc ] initWithFrame:CGRectMake((self.bounds.size.width/2), 0.0, 150.0, 43.0) ]; 
scoreLabel.textAlignment = UITextAlignmentCenter; 
scoreLabel.textColor = [UIColor whiteColor]; 
scoreLabel.backgroundColor = [UIColor blackColor]; 
scoreLabel.font = [UIFont fontWithName:@"Arial Rounded MT Bold" size:(36.0)]; 
[self addSubview:scoreLabel]; 
scoreLabel.text = [NSString stringWithFormat: @"%d", score]; 

myTimer = [NSTimer scheduledTimerWithTimeInterval:60 target:self selector:@selector(changeLabel) userInfo:nil repeats:YES]; 

-(void)changeLabel { 
    scoreLabel.text = [wordArray objectAtIndex:cntr]; 
    cntr++; 
    if(cntr==100) [myTimer invalidate]; 
} 
+0

提示:输入密码时,请记住突出显示密码并点击“密码”图标。这将使读取代码示例变得更容易。 – dredful 2010-11-04 21:19:03

回答

0

wordArray是一个NSMutableArray

NSMutableArray *wordArray; 

在你的头文件,并

wordArray = [NSMutableArray arrayWithObects:@"Several",@"Words",@"Here",nil]; 

OR

wordArray = [NSMutableArray array]; 
[wordArray addObject:@"Several"]; 
[wordArray addObject:@"Words"]; 
[wordArray addObject:@"Here"]; 

为例添加到它。

+0

好吧,谢谢,我必须将每个单词wordArray单词连接到NSTimer?或者有[wordArray objectAtIndex:cntr];控制何时全部改变? – BasicApp 2010-11-04 21:32:43

+0

你是否在一个地方添加了所有单词?或者你是否逐渐增加词语取决于其他因素? – Ben 2010-11-04 21:41:47

+0

我一次添加所有单词,然后希望程序在整个屏幕上每隔60秒完成一次。但最终我会添加更多,但即时通讯假设我只是编辑程序并重置它时,我这样做。 – BasicApp 2010-11-04 21:42:54