在将固件下载到设备时更新进度指示器

shr*_*ads 0 cocoa

我正在开发一个将固件下载到设备的cocoa应用程序.使用NSProgressIndicator显示下载进度.我-incrementBy:在while循环中调用DeviceRequestTO方法之后的NSProgressIndicator方法.但只有在将整个固件写入设备后才会更新进度指示器.它显示100%完成一次.所以我添加了-displayIfNeededNSView类的方法.现在它可以顺利显示进度,但这也会在固件下载完成后发生.如何同时实现进度指示和写入操作?

以下是代码:

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];
}
Run Code Online (Sandbox Code Playgroud)

Pet*_*sey 5

你需要调用的方法setNeedsDisplay:不是displayIfNeeded.后者意味着" display如果有人发给你,就发送给自己setNeedsDisplay:YES".如果你不做最后一部分,视图不知道它应该显示,并且displayIfNeeded什么也不做.

一旦你添加了setNeedsDisplay:消息,你就可以删除displayIfNeeded消息,因为框架会定期将该消息发送到窗口(因此,它的所有视图).