views:

922

answers:

2

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.

+5  A: 

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.

Louis Gerbarg
+1 for pointing out users' expectations on the iPhone. Read the Human Interface Guidelines for more: http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/MobileHIG/Introduction/Introduction.html
Tim
I need a alertView because, i want to place a cancel button inside the alert view. thats how user can cancel the uploading.
faisal
You can have a cancel button and put it somewhere else in the main UI, there is nothing wrong with that. Trust me, you don't want to do this as an alert. Do you really expect your users to sit there staring at an alert while you upload data over an EDGE connection? If you do that I guarantee you that users will hit the cancel button a lot, but that isn't a good thing, since they will be hitting it because they are bored or frustrated.
Louis Gerbarg
+2  A: 

I know you are asking about doing it in an Alert, but you might want to checkout http://github.com/matej/MBProgressHUD

lottadot