Hi iPhone application developers,
I am developing an iphone application. This application allows a user to upload images to my server. I want to show the upload progress in an alertView. I need some example code to illustrate how to implement a custom UIAlertView with a progress bar.
Thanks in advance.
You can subclass the UIAlertView. I have done something like this, change it for your need.
Header file,
Source code,
I know you are asking about doing it in an Alert, but you might want to checkout http://github.com/matej/MBProgressHUD
The "fast" way to do this is to take a UIAlertView and reposition its internal subviews to shove your progress bar into it. The downside of that is it is fragile and is likely to break in the future.
The correct way to do this requires implementing a subclass of UIWindow that is layed out like you want and set its windowLevel to UIWindowLevelAlert so that it draws in front of your current window. It should be fairly easy to get something working, but getting it to look like one of the builtin alerts will take a lot of effort.
Before you do either of those though, I would suggest you rethink your UI. Why should your application block while it is uploading. Why not just put a status bar somewhere on the screen and let the user keep interacting with the application while you do the upload in asynchronously. Take a look at how the Messages app works while it is uploading an MMS for an example of what I am talking about.
Users hate it when an application blocks them while something is going on, especially on the iPhone where there is no multitasking.