1

I'm using a NSTimer in a NSObject class (Timer), that fires a method, that increments a variable and fires a method in a View Controller (InfoViewController). (Confused ;-D )

Everything shows up on the screen and and the timer is started correctly. The variable f.hunger updates and shows the correct value (when using printf("%f", f.hunger) ) but the UIProgress bar doesn't update itself. f.hunger's starting value is 1.

If anyone can help me, point out where I've made an obvious mistake or got a suggestion it would be most appreciated as it's been doing my head in for a good few hours now. I've added some sample code below to show what I'm doing a bit more clearly.

Cheers everyone. :-D

Timers Class

- (void)startHungerTimer
{
 if(hungerTimer.isValid == NO)
 {
  infoVC = [[InfoViewController alloc] init];
  self.hungerTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:self     selector:@selector(incrementHungerTimer:) userInfo:nil repeats:YES];
 }
}

- (void)incrementHungerTimer:(NSTimer *)aTimer
{
    f.hunger -= 0.01;
    [infoVC updateHungerProgress];
}

Info View Controller

- (void)updateHungerProgress
{
 Functions *f = [Functions sharedFunctions];
 hungerBar.progress = f.hunger;        
}

- (void)loadView
{
    hungerBar = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
    [hungerBar setFrame:CGRectMake(17.0, 30.0, 160.0, 10.0)];
    hungerBar.progress = f.hunger;
    [bView addSubview:hungerBar];
    [hungerBar release];
}
4

1 回答 1

0

鉴于您的问题和评论,我的猜测是您的“hungerBar”插座未连接到 Interface Builder 中的进度条。

于 2010-12-14T15:20:00.077 回答