我正在開發將固件下載到設備的可可應用程序。使用NSProgressIndicator顯示下載進度。在while循環中的DeviceRequestTO方法之後,我調用NSProgressIndicator的-incrementBy:
方法。但是隻有在整個固件寫入設備後,進度指示器纔會更新。它一次性顯示100%完成。所以我添加了NSView類的-displayIfNeeded
方法。現在它可以順利地顯示進度,但是也會在固件下載完成後出現。我怎樣才能同時完成進度指示和寫入操作?將固件下載到設備時更新進度指示器
以下是代碼:
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];
}
此方法在一個單獨的線程?如果是這樣,你必須使用-performSelectorOnMainThread更新UI:你能發佈你的代碼嗎? – 2009-01-08 10:32:38