1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Problem with a NSProgressIndicator

Discussion in 'Mac Programming' started by mpemburn, Jun 24, 2009.

  1. macrumors member


    I've added an NSProgressIndicator to the splash screen of my app (since it can take a while to locate the resources necessary to load the main window). I wanted to have a "Bar" type indicator but nothing I've been able to do will make it move as it should. When I change it to the "Spinning" type, it works just fine but the Bar just sits there.

    The indicator is connected to the app controller via:

    IBOutlet NSProgressIndicator * splashProgress;
    . . . and this is the code that runs it:

    [splashProgress setHidden: NO];
    [splashProgress startAnimation: self];
    Any ideas?

    -- Mark
  2. Moderator emeritus


    Are you sure the indeterminate checkbox is on in IB?
  3. macrumors member

    Wow -- that was fast! Yes, it's checked.

    -- Mark
  4. Moderator emeritus


    I'd double-check your IB connections. Make sure you're calling the code after/during awakeFromNib (e.g. make sure your progress is non-nil). etc..
  5. macrumors member

    The IB connections are definitely there and working and the code that calls loads the splash screen (including the calls to the progress indicator) is right at the top of awakeFromNib. In order to prove that the connection is valid, I've comment out the "startAnimation" line, and see a stopped spinner when the screen loads. When I un-comment it again, the spinner animates. If I add the line:

    [splashProgress setStyle: NSProgressIndicatorBarStyle];
    . . . it'll change to the bar style but not move.

    -- Mark
  6. macrumors regular

    If you want it to show the progress, indeterminate should be off. Indeterminate means that it does NOT show the amount of progress, but only that the application is "busy".

    Are you updating the progress value with setDoubleValue regularly throughout your loading process?
  7. macrumors member

    In this case, I don't really have any progress to show -- it's waiting for a dylib to recognize all imaging devices attached to the system -- so "indeterminate" is the appropriate mode. Like I have said, the Spinner works in indeterminate mode and the Bar does not.

    Think I'll try a dummy project to see if the problem is universal or some quirk in this app. I've had some other annoying phenomena, such as controls that stop appearing after I make some unrelated change to the panel. I would just hate it if there's something wrong with the NIB -- I've put a lot of time into this interface.

    -- Mark
  8. Moderator emeritus


    The only other thing I can think of is the progress bar is somehow being blocked from animating, but I believe on 10.5+ the default is setUsesThreadedAnimation:YES so that shouldn't be a problem even if you're blocking the main thread. I would agree on the dummy project because I think either something is borked with your project or you're just forgetting to do something small.
  9. macrumors G4


    I've had problems with NSProgress indicators if I didn't do the work in another thread so that is probably the best way forward.
  10. macrumors member

    Figured out an acceptable workaround -- set the values to: Minimum = 0.0, Maximum = 100.0 and Current = 99.0. As long a the bar is reasonably short, there's no visible difference between being 99% done and 100% done so the bar shows motion across its full length.

    -- Mark
  11. macrumors newbie

    Wow, spent 1/2 hr putting my code in the INIT and wondering why it was not working.

    Moving it to AWAKEFromNib made it to work. Thanks for the tip

    [progressIndicator setHidden:NO];
    [progressIndicator setIndeterminate:YES];
    [progressIndicator setUsesThreadedAnimation:YES];
    [progressIndicator startAnimation:nil];

  12. macrumors 6502a

    Yeah, awakeFromNib is called after all the Outlet connections are set up. If the code is in init then those connections aren't set up yet and your calls would be no-ops.

Share This Page