显示按钮后如何在 UIAlertView 上显示按钮

发布于 2024-08-04 16:14:03 字数 1319 浏览 1 评论 0原文

我是使用 Objective C 进行开发的新手。

我正在编写一段代码,将插件安装到我的应用程序中。它下载一个 .zip 包,解压缩并将一些数据复制到我的 sqlite 数据库中。

我有一个 UIAlertView,在应用程序下载和解压缩时显示 UIProgressView,完成后我向 UIAlertView 添加一个带有 UIAlertView 的按钮代码>addButtonWithTitle方法。

我不知道为什么我的按钮出现在 UIAlertView 的左上角。

这是我的代码的一部分:

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";

我有一张图像,但我无法将其发布在这里,因为我是新用户。

任何人都知道为什么我的按钮出现在 UIAlertView (ventana) 的左上角 谢谢!

I am newbie developing with objective C.

I am 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 because I am a new user.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

能怎样 2024-08-11 16:14:03

您使用 UIAlertView 的方式有点......不好。您不应该永远显示带有 0 个按钮的 UIAlertView,并且将其用作“不要关闭设备”消息是一个坏主意。警报视图的“可接受”用途是告诉用户刚刚发生了一些重要的事情。但是,如果您坚持,默认情况下应该有一个取消按钮,以便他们可以根据需要停止操作,然后在完成后添加该按钮。当尝试将按钮添加到不存在的按钮列表中时(因为您使用 0 个按钮对其进行了初始化),UIAlertView 可能会感到困惑。

但是,更好的方法是在通用 UIView 上下载(您已经拥有)时显示进度指示器,并使用包含消息的 UILabel 。然后,完成后,更改标签以显示“Instalación Finalizada”消息,并在其下方显示一个按钮。我知道,它似乎只是复制您已有的内容,但我在您的描述中没有看到任何地方需要使用 UIAlertView

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文