views:

622

answers:

1

Hi, im newbie developing with objc.

Im working on a piece of code that installs a plugin to my application. It downloads a .zip package, uncompress it and copy some data to my sqlite database.

I have a UIAlertView that shows a UIProgressView while the app is downloading and uncompressing, when it finish I add to the UIAlertView a button with the addButtonWithTitle method.

I dont know why my button appears on the top-left corner of my UIAlertView.

This is a piece of my code:

ventana = [[UIAlertView alloc] initWithTitle:[[NSString alloc] initWithFormat: @"Instalando %@", codigo] 
                  message:@"Por favor, no apague el dispositivo ni cierre la aplicación." delegate:nil cancelButtonTitle:nil  otherButtonTitles: nil];

actividad = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
actividad.frame = CGRectMake(20, 110, 20, 20);

progreso = [[UIProgressView alloc] initWithFrame:CGRectMake(50, 115, 215, 9)];
[ventana addSubview:actividad];
[actividad startAnimating];
[ventana addSubview:progreso];
[ventana show];

-- some stuff (downloading, uncompressing, updating my UIProgressView...) --
[progreso removeFromSuperview];
[actividad removeFromSuperview];
[ventana addButtonWithTitle:@"Aceptar"];
ventana.message = @"Instalación finalizada";

I have a image but I can't post it here cos im a new user... :(

Anyone knows why my button appears at the top-left corner of my UIAlertView (ventana) Thanks!

+2  A: 

The way you are using the UIAlertView is sort of... bad. You should nevershow a UIAlertView with 0 buttons, and using it as a 'don't turn off the device' message is a bad idea. The "accepted" use for the alert view is to tell the user something important has just happened. If you insist, however, you should have a cancel button in there by default so they can stop the operation if they want to, then when it's finished, add the button. The UIAlertView may be confused when trying to add a button to a list of buttons that doesn't exist (because you initialized it with 0 buttons).

However, the better way to go about it would be to show a progress indicator while downloading (which you have) on a general UIView with a UILabel containing the message. Then, when it's completed, change the label to show your "Instalación finalizada" message, and display a button below it. I know, it seems like it's just replicating what you already have, but there's nowhere in your description that I see that calls for the use of a UIAlertView.

Ed Marty
OK, I have put an initial cancel button, but my final accept button stil appears at the top-left corner of the UIAlertView.I'm using the UIAlertView because I want an small window with the UIAlert style (transparet blue, rounded corners, etc.) Can I do it with an UIView? or it's wrong too?Thanks
Centauro12
It doesn't matter whether you actually use a UIAlertView or replicate the way it looks. Conceptually, it's the same to the end user, and that's what the Apple HIG is talking about when it says when and when not to use a UIAlertView.
Ed Marty