开发者

Using MBProgressHUD with asynchronous NSURLConnection?

I am trying to get the code found here:

http://snipplr.com/view/26643/mbprogresshud开发者_如何转开发-with-an-asynchronous-nsurlconnection-call/

to work in my project. It's using the private MBProgressHUD class however i keep getting exc_bad_access errors on lines 69 or 70 depending if you comment out the log statement:

NSLog(@"float filesize: %f", [self.searchResultFileSize floatValue]); HUD.progress = [resourceLength floatValue] / [self.searchResultFileSize floatValue];

The problem is with the conversion of searchResultFileSize to a floatValue although i cant figure out why. A call to the same variable one line up

NSLog(@"filesize: %d", self.searchResultFileSize);

works fine. Only idea i have come up with is that it might be some threading issue??

Any ideas?? Or does anyone have a working example of how to use MBProgressHUD with asynchronous NSURLConnections?

P.S. I tried using the original MBProgressHUD code which specifies a call like:

[HUD showWhileExecuting:@selector(myProgressTask) onTarget:self withObject:nil animated:YES];

However this didn't work because myProgressTask uses a NSURLConnection which is uses a delegate so the code above would execute for the method call to myProgressTask and then hide itself before the response came back.


When you do

NSLog(@"filesize: %d", self.searchResultFileSize);

you are printing out the integer value of a pointer to an NSNumber, I think (line 53 assigns a pointer to an NSNumber to searchResultFileSize). On line 53, the NSNumber that is returned and assigned to searchResultFileSize is autoreleased--it looks to me as though it's probably getting dealloc'd between there and when you try to access it on line 69. Even if it's dealloc'd, it will still have an integer value of the pointer, so

NSLog(@"filesize: %d", self.searchResultFileSize);

will work, but any attempt to call a method of the instance of NSNumber to which it should point will fail with exc_bad_access. However, without seeing the interface definitions, particularly where searchResultFileSize is defined, I cannot tell for sure.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜