Updating the progress indicator when downloading the firmware to the device

I am developing a cocoa app that downloads firmware to a device. Download progress is shown using NSProgressIndicator. I am -incrementBy:

calling the NSProgressIndicator method after the DeviceRequestTO method in a while loop. But the progress indicator is updated only after all the firmware is written to the device. It shows 100% completion in one move. So I added a method to -displayIfNeeded

the NSView class. It now shows progress smoothly, but it also happens after the firmware download is complete. How can I perform progress bar and recording at the same time?

Below is the code:

while(1)
{
    int result = (*dev)->DeviceRequestTO(dev, &request);
    printf("\nBlocks Written Successfully: %d",DfuBlockCnt);
    [refToSelf performSelectorOnMainThread:@selector(notifyContent)
                        withObject:nil
                        waitUntilDone:NO];
}

//In main thread
- (void)notifyContent{
    [dnldIndicator incrementBy:1];
    [self displayIfNeeded];
}

      

0


source to share


2 answers


The method you need to call is - setNeedsDisplay:

, not displayIfNeeded

. The latter means "send yourself display

if someone sent you setNeedsDisplay:YES

". If you don’t do this last part, the view doesn’t know that it should be displayed and will displayIfNeeded

do nothing.



And as soon as you add the message setNeedsDisplay:

, you can cut the message displayIfNeeded

, as the environment will still send that message to the window (and therefore to all of its views).

+5


source


Your code looks exactly the same as some I use to update UIProgressIndicators and NSProgressIndicators on Mac and iPhone, code that works great for me. I am assuming, like menumachine, that your while loop exists on a background thread (created with performSelectorInBackground: withObject: or NSThread detachNewThreadSelector: toTarget: withObject :).

Are the minValue and maxValue parameters of the progress indicator adjusted correctly (0 and 100 or regardless of scale)?



How often do updates happen? Perhaps you are dispatching too many events too quickly and the UI is unable to update correctly.

This code should work as far as I can tell.

0


source







All Articles