Domanda

I'm using a NSProgressIndicator in my xcode project (Mac OS X, not iOS). I'm trying to do an async download of a file, while showing the progress of the download on a progress indicator. In my project, clicking on the update button starts the download. After each time data is received, progress is updated, and the update_progress method in the app delegate is called.

As you can see from the NSLogs, the progress value is passed on to that method. Using setDoubleValue on the progress indicator with this value, has no effect. However, using a static value (e.g. setDoubleValue:50.0f) does update the progress indicator.

In .m, the loadData method starts the download. Here you can set the location to save the file (self.strFileNameWithPath), and a few lines below, the location to download the file from. I'm just using a file of 2.5mb, small, but big enough to have a few download steps.

In the interface, click the "update" button to start the download. The console will show progress updates, as chunks are received.

Would anybody know any reasons to why this is happening, and how I could fix it? Thanks in advance!

Edit: The method with the inconsistency is:

- (void)update_progress:(float)value{
    double thevalue = (double)value;
    NSLog(@"value: %f",thevalue);
    [self.progress_indicator setDoubleValue:thevalue];
    NSLog(@"Prgoress: %f",[self.progress_indicator doubleValue]);
}

During each progress step, value shows the correct progress value, but the progress indicator isn't reacting to setDoubleValue since the second NSLog returns 0.0.

Below is what the console shows:

value: 2.770802
Prgoress: 0.000000
value: 22.662386
Prgoress: 0.000000
value: 69.881004
Prgoress: 0.000000
È stato utile?

Soluzione

The problem was my init method, the following in the downloader implementation fixed it:

- (id)init{
    self = [super init];

    if (self) {
        appdelegate = [[NSApplication sharedApplication] delegate];
    }

    return self;
}

So much for quick coding to try something, I feel silly...

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top