简体   繁体   English

UIProgressView 未在 iPhone 上显示,但在模拟器中显示

[英]UIProgressView not showing on iPhone but shows in simulator

I have a UIProgressView called progTimer that I placed on my View Controller via Interface Builder.我有一个名为UIProgressViewprogTimer ,我通过 Interface Builder 将它放在我的 View Controller 上。 On the iOS simulator, the UIProgressView shows up just fine, but when I test it on my iPhone it doesn't appear.在 iOS 模拟器上, UIProgressView显示得很好,但是当我在我的 iPhone 上测试它时它没有出现。

Here is the code that modifies it.这是修改它的代码。

- (IBAction)scanbtn
{
    [progTimer invalidate];//cancels timer if currently running
    progTimer=nil;
    progNum = 0;
    progTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 //timer to update the progress view
                                               target:self 
                                             selector:@selector(progIncrease)
                                             userInfo:nil
                                              repeats:YES];
    [self scan];
}
-(void) progIncrease
{
    progNum = progNum + 0.01;
    scanProg.progress = progNum;
    if (progNum >=1)
    {
        [progTimer invalidate];
        progTimer=nil;
        //[alert show];
    }
}

Any ideas?有任何想法吗? Thanks in advance.提前致谢。 . .

ALL: For some reason, I changed the style of the Progress View to "Bar" and it shows up fine. ALL:出于某种原因,我将 Progress View 的样式更改为“Bar”,它显示得很好。 No idea what caused the initial problem, but now it works albeit having a different style bar.不知道是什么导致了最初的问题,但现在它可以工作,尽管有不同的样式栏。

My guess would be that on the device, the scanning process is moving so fast that you just can't see it.我的猜测是,在设备上,扫描过程进展得如此之快,以至于你根本看不到它。 To make sure it's working ad and NSLog in the ProgressIncrease method to see how fast it scans.确保它在 ProgressIncrease 方法中工作广告和 NSLog 以查看它的扫描速度。 I had the same problem with my preloading notifiers, that were showing on the simulator but not on the device.我的预加载通知器也有同样的问题,它显示在模拟器上,但没有显示在设备上。

You call [self scan];你叫[自我扫描]; which seems to be the culprit.这似乎是罪魁祸首。 How long does that scan operation run?该扫描操作运行多长时间?

Its very important to note that while any long running operation runs in main thread which is UI thread, no other code in the main thread loop will be executed(until that long running operation finishes) which means your timer function or even pressing button after pressed once pressed won't work.非常重要的是要注意,虽然任何长时间运行的操作在主线程(即 UI 线程)中运行,但不会执行主线程循环中的其他代码(直到长时间运行的操作完成),这意味着您的计时器 function 甚至按下按钮后按下一旦按下将不起作用。 You need to use either NSOperation and dispatch queue or create a thread and run the scan operation in the background and send notifications to main thread using NSMachPort or NSObject performSelectr:OnThread:... etc for it to update the progress bar.您需要使用 NSOperation 和调度队列或创建一个线程并在后台运行扫描操作并使用 NSMachPort 或 NSObject performSelectr:OnThread:... 等向主线程发送通知以更新进度条。

By the way, the scanning process and the progress bar has no relation at all;顺便说一句,扫描过程和进度条完全没有关系; The progress bar should ideally update how much of scanning is done which means the scanning process must inform progress bar to update that also in main thread if scanning is running in secondary thread.理想情况下,进度条应该更新完成了多少扫描,这意味着如果扫描在辅助线程中运行,扫描过程必须通知进度条在主线程中更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM