4

I am trying to increment progress bar and show percentage on a label. However, both remains without changes when "incrementaProgres" function is called. IBOutlets are properly linked on xib and also tested that, when function is called, variables have proper value. Thanks

from delegate:

loadingViewController *theInstanceP = [[loadingViewController alloc] init];
[theInstanceP performSelectorOnMainThread:@selector(incrementaProgres:) withObject:[NSNumber numberWithFloat:0.15] waitUntilDone:YES];

loadingView class:

- (void)viewDidLoad
{
    [super viewDidLoad];

    [spinner startAnimating];
    [progress setProgress:0.0];
}

- (void)incrementaProgres: (CGFloat)increment{

    [progress setProgress:(progresInc + increment)];
    carrega.text = [NSString stringWithFormat: @"%f", (progresInc + increment)];

}
Jaume
  • 3,672
  • 19
  • 60
  • 119

2 Answers2

4

Progress bar's progress value is between 0.0 and 1.0, your code sets it in the increments of 15.0, which is out of range. Your increment should be 0.15, not 15.0.

Sergey Kalinichenko
  • 714,442
  • 84
  • 1,110
  • 1,523
  • Thanks, android made me forget iOS pb basics :) However, still not refreshing although vars have proper value... – Jaume Apr 12 '12 at 10:36
  • 1
    @Jaume is `carrega.text` being set to the correct value between 0 and 1? – Sergey Kalinichenko Apr 12 '12 at 10:40
  • carrega label does the same, is set at assigned value but not updated on view – Jaume Apr 12 '12 at 10:53
  • @Jaume Once it sets the label and the progress bar value, does your code return control all the way back to the run loop? The label and the progress bar would not get updated until you return from a method that services the iOS message sent to your application. – Sergey Kalinichenko Apr 12 '12 at 10:56
  • I'm not sure I understand exactly what you mean... once the instance is triggered, method that call it follows executing the loop. Or do you mean to call it on a separate NSThread? – Jaume Apr 12 '12 at 11:32
  • mmm please see edits, performSelectorOnMainThread: ensure that returns to main loop when pb is incremented. However, still not displaying the progress – Jaume Apr 12 '12 at 12:22
  • @Jaume Take a look at [this answer](http://stackoverflow.com/a/8804319/335858) explaining how to deal with the dispatch part of the problem. – Sergey Kalinichenko Apr 12 '12 at 12:42
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/10009/discussion-between-jaume-and-dasblinkenlight) – Jaume Apr 12 '12 at 15:12
2

Progress is a value between 0.0 and 1.0.

Edit: Did you try to call [myView setNeedsDisplay];?

2nd Edit:

Maybe there is one confusion: viewDidLoad is called right before you are presenting the view. Therefore in the code you have shown here incrementaProgres: is called before viewDidLoad.

dasdom
  • 13,975
  • 2
  • 47
  • 58
  • thanks, edited but same issue... seems that fill var values properly but is not refreshing... – Jaume Apr 12 '12 at 10:37
  • do you mean something like [progress performSelectorOnMainThread:@selector(setNeedsDisplay) withObject:nil waitUntilDone:YES]; ? added but same issue... – Jaume Apr 12 '12 at 10:52
  • related to 2nd Edit, viewDidLoad was previously triggered and view was already on a superView, after that, incrementaProgres is called – Jaume Apr 12 '12 at 11:33
  • The UIProgressView looks fine, the issue seems elsewhere in your code, probably in your nib file itself. – nitin k m p Mar 08 '13 at 08:12