views:

153

answers:

1

Hello,

I have a section of code that uploads an image:

[activity startAnimating];
 [self uploadImage:img Session_id:appDelegate.sessionID PlaceID:place.placeID Comment:comment.text];
 [activity stopAnimating];

I am sure that activity is wired up correctly to a UIActivityViewIndicator, but it never shows. Inside the uploadImage function, I open a connection to the server and start the upload. Does anyone have an example or possible explanation as to why the activity view would not display?

+2  A: 

If you're doing the upload on the main thread, then it's blocked and the UI cannot be updated.

I would suggest running it on a background thread.

Tom Irving
have a look at the NSURLConnection and NSURLRequest (and its mutable friend). They will enable you to make connections and requests to web services asynchronously, leaving your main thread and UI unblocked.
Jasarien