1

我想制作一个“正在下载”的 uilabel,当我调用“更新”方法时,它的标签文本会动态变化:

self.checkingArray = [NSArray arrayWithObjects:@"download", @"download.", @"download..", @"download...",
                 nil];

- (void) updating
{
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(changeText) userInfo:nil repeats:YES];
}

- (void) changeText
{
    checkLabel.text = [self.checkingArray objectAtIndex:curCheckingState];

    self.curCheckingState++;

    if (self.curCheckingState >= 4) {
    self.curCheckingState = 0;
}

但是标签文字与文字“下载...”保持一致,我想知道如何达到我的目的?

4

2 回答 2

3

实现这个:

- (void) updating
{
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(changeText) userInfo:nil repeats:YES];
}

- (void) changeText
{
    static unsigned char state = 0;

    checkLabel.text = [self.checkingArray objectAtIndex:state];

    if(state < 3) state++;
    else state = 0;
}
于 2012-06-17T14:53:07.100 回答
1

做这个:

self.checkingArray = [NSArray arrayWithObjects:@"download", @"download.", @"download..", @"download...",
             nil];
self.curCheckingState = 0;


- (void) updating
{
 //change timer time interval if needed
 NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(changeText) userInfo:nil repeats:YES];
}

- (void) changeText
{
  checkLabel.text = [self.checkingArray objectAtIndex:self.curCheckingState];

  if (self.curCheckingState == 3) //depending on [array count]-1
  {
    self.curCheckingState = 0;
  }
  else
  {  
    self.curCheckingState++;
  }

}

于 2012-06-17T14:54:59.713 回答