Please Wait iPhone - No NSTimer
I am currently using NSTimer
to load a "开发者_运维问答Please Wait" alert view in my application while it contacts a server. I want to get rid of this NSTimer
and change it so that it runs the "Please Wait" alert view in a loop until it gets a response from the server.
How would I do this?
A loop would be bad (blocking the main thread), but if you use NSURLConnection
object you get a connectionDidFinishLoading:
message in the delegate.
- You pop up the alert when you start the connection.
- You dismiss the alert in the
connectionDidFinishLoading:
of your delegate.- And also when an error occurs.
Though I agree with @Radu when it's about user experience.
Set up a delegate for the NSURLConnection. Your delegate will then receive messages at interesting points in the connection, such as when data is received and when the connection is finished.
try this page. It helps manage cases where there might be more than one network event going on.
精彩评论