2

I've got magazine app. There is UITableView which contains custom cells. In each cell is button, icon, title and hidden UIProgressView. When someone tap to button, pages (images) are starting to download. When some page is downloaded, I want to show hidden UIProgressView or update. And there's the problem. I'm using NSNotification and performSelectorOnMainThread for updating UIProgressView. But the UIProgressView doesn't show. I don't know where error is... Thx for reply!

There's some code... Creating UIProgressView:

self.progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
[self.progressView setFrame:CGRectMake(250, 200, 92, 28)];
[self.progressView setProgress:0.0];
[self.progressView setHidden:YES];
[self.cellView addSubview:self.progressView];

Posting notificaiton:

[[NSNotificationCenter defaultCenter] postNotificationName:kDownloadedIcon object:nil userInfo:dict];

Accepting notification:

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(iconDownloaded:) name:kDownloadedIcon object:nil];

Resend notification to main thread:

- (void)iconDownloaded:(NSNotification *)notification {
[self performSelectorOnMainThread:@selector(updateProgressBar:) withObject:notification waitUntilDone:YES];}

Update or show UIProgressView:

- (void)updateProgressBar:(NSNotification *)notification {
NSDictionary *dict = [notification userInfo];

NSLog(@"%@ %@ %@", [dict objectForKey:@"name"], self.identifier, self.progressView);

if ([[dict objectForKey:@"name"] isEqualToString:self.identifier]) {
    if (self.spinner) [spinner stopAnimating];
    self.spinner = nil;
    [self.spinner removeFromSuperview];

    [self.progressView setHidden:NO];
    self.progress++;
    NSInteger count = [[dict objectForKey:@"pages"] intValue];
    [self.progressView setProgress:self.progress/count];
}
prashant
  • 1,920
  • 14
  • 26
Michal Jurník
  • 820
  • 1
  • 8
  • 23
  • Does your `NSLog` inside `-updateProgressBar:` show up in the console? – Tim Sep 10 '12 at 15:17
  • Yes, console wrote everythings fine. – Michal Jurník Sep 10 '12 at 15:39
  • Can you set a breakpoint right before you call `[self.progressView setHidden:NO]`? Check to see what `self.progressView` is (make sure it's not `nil`), look at its frame, its superview, etc. – Tim Sep 10 '12 at 17:22
  • Try it. `self.progressView` is never nil. Could it be any problem with drawing? – Michal Jurník Sep 11 '12 at 06:30
  • 1
    Can you update your post with the names of the classes that have each of the code snippets you posted? For example, what class creates the UIProgressView? – Tim Sep 11 '12 at 14:33
  • 1
    A sample project works for me. In addition to the class information, can you look at the frame of your progress view and the frame of your `cellView`? It's possible you're placing your progress view outside your cell's visible area and just not noticing right away since you set it hidden. – Tim Sep 11 '12 at 14:55
  • Thx for interest Tim. Progress view is in cell, I try it display before I hide it. UIProgressView is created when I'm creating cellView. So I create progress view in my `CustomCell : UITableViewCell`. Could u give me the sample project which you've created? – Michal Jurník Sep 11 '12 at 17:06
  • See [this project](https://github.com/lithium3141/SO-ProgressViewTest) on GitHub. – Tim Sep 11 '12 at 17:37

1 Answers1

1

Hurray! Thx Tim for ideas! Your "simple project" helped me to solved it. Problem was, I start for loop. In this loop I'm posting notifications. But when for starts, it blocks main thread and UI hasn't been redrawn. So I sent calling of for loop to background and everything works fine. Thx again Tim

Michal Jurník
  • 820
  • 1
  • 8
  • 23