1

メソッド「updating」を呼び出すと、ラベルテキストが動的に変化する「ダウンロード」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 に答える