0

Kinda stuck on this problem and I'm not sure, where I've gone wrong. Heres what I'm doing:

Class calls:

- (void)updateApplicationDataInBackground {


updateView = [[UpdatingView alloc] init];
[self.view addSubview:updateView.view];


DataSynchronizer *dataSynchronizer = [[DataSynchronizer alloc] init];

[NSThread detachNewThreadSelector:@selector(initWithDataRequest:) toTarget:dataSynchronizer withObject:self];

[dataSynchronizer release];

This creates a thread to retrieve data from the server and parse it. In DataSynchronizer this is the method being called:

- (void)initWithDataRequest:(id)parent {

NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

controller = parent;

NSLog(@"DataSynchronizer initWithDataRequest called");

NSURL *url = [NSURL URLWithString: ApiUrl]; 

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:ApiKey forKey:@"key"];
[request setPostValue:ApiPass forKey:@"password"];
[request setPostValue:@"somevalue" forKey:@"framework"];
[request setPostValue:@"somevalue" forKey:@"method"];
[request setDidFinishSelector:@selector(parseResult:)];
[request setDidFailSelector:@selector(requestError:)];
[request setTimeOutSeconds:60];
[request setDelegate:self];
[request startAsynchronous];


[pool release];

After my data is received I parse the contents and do my data synch. This is all working as expected. I've decided to throw in a UIProgressView so the user can see what is going on with this request, this progress view lives in updateView which is created in the updateApplicationDataInBackground.

I'm not trying to show progress for the web service call but simply when milestones are reached in the data processing. In the DidFinishSelector its calling parseResult

There are five method its calls with the response data:

[self parseData:[data objectForKey:@"types"] forObject:[Types class] andParent:nil];
        [controller performSelectorOnMainThread:@selector(updateProgress:) withObject:[NSNumber numberWithFloat:.4] waitUntilDone:YES];

After each process I'm trying to update the UIProgressView, it will never update. Now if I simply call performSelectorOnMainThread from outside the ASIHTTPRequest it works as expected, but not within the DidFinishSelector. I've tried many variations on this where it calls a local method which updates the mainThread, where I simply use performSelector. Nothing works, how do I update the the UIProgessView?

Is the problem a thread spawning a thread?

Thanks

EDIT:

Looks like the DidFinishSelector is being called on the main thread already. I've updated my code to simply call:

[controller updateProgress:[NSNumber numberWithFloat:.8]]

Still no luck....

Realized it might be helpful to see the UIProgessView update method.

- (void)updateProgress:(NSNumber *)progress {


float newProgess = [progress floatValue];


[updateView.myProgress setProgress: newProgess];
downed
  • 343
  • 1
  • 9

1 Answers1

1

Ok so it looks like I found my own answer after changing somethings around. Because ASIHttpRequest performs SetDidFinish selector on the main thread my calls performSelectorOnMainThread weren't doing anything. I changed my initial call for the DataSynchronizer to the main thread and added changed the DidFinish method to:

- (void)parseDataInBackground:(ASIHTTPRequest *)request {   

[NSThread detachNewThreadSelector:@selector(parseResult:) toTarget:self withObject:request];

Which then makes the parse method run on separate thread (since its the bulk of the processing and now performOnMainThread works without issue.

downed
  • 343
  • 1
  • 9