簡體   English   中英

UIProgressView進度未更新

[英]UIProgressView progress doesn't updated

我有一個UIProgressView添加到self.view作為子視圖。 我有一個加載行的UITableView。 我需要每一行中的圖像,但我不希望應用程序等待所有這些,所以我決定運行NSThread並加載圖像進程。 當我嘗試從我的線程內部更新UIProgressView的進度時 - 它沒有得到更新。 我是否需要實施一些代表?

初始化

    progressView = [[[UIProgressView alloc] initWithFrame:CGRectZero] autorelease];
    [progressView setFrame:CGRectOffset(CGRectMake(0, 0, 320, 8), 0, 1)];
    [self.view addSubview:progressView];

然后我運行我的線程

    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    [progressView setProgress:0.0];
    NSThread *myThread = [[NSThread alloc] initWithTarget:self
                                                 selector:@selector(imageLazyLoading)
                                                   object:nil];

    [myThread start];
    [pool release];
    [myThread release];

然后我嘗試更新它

CGFloat pr;
for(int i=0; i < [self.itemsToDisplay count]; i++){
    if (!runThread) {
        return;
    }
    pr = (CGFloat)i/(CGFloat)[self.itemsToDisplay count]; 
    [self performSelectorOnMainThread:@selector(updateProgressBar:)
                           withObject: [NSNumber numberWithFloat:pr]
                        waitUntilDone: YES];
    progressView.progress += 0.5;.............

什么都沒有......

您所要做的就是更新主線程上的Progressview 這是關於它的文章。 http://www.xprogress.com/post-36-threading-tutorial-using-nsthread-in-iphone-sdk-objective-c/

iOS 5.0也遇到了同樣的問題。 似乎直到5.0,您可以從任何線程更新'progress'變量,但必須從主線程調用setNeedsDisplay。 從5.0開始,您還必須從主線程設置'progress'值。 希望它可以幫助任何人。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM