gpt4 book ai didi

iphone - 在运行时在 UIAlertview ios 中添加确定按钮

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:46:37 24 4
gpt4 key购买 nike

我在调用 Web 服务时使用进度指示器 View 调用警报。我正在设置这样的警报 View :

    [self.activityIndicatorView setHidden:NO];
self.alertView = [[UIAlertView alloc] initWithTitle:@"Sending Login Request.."
message:@"\n"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:nil];

self.activityIndicatorView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
self.activityIndicatorView.center = CGPointMake(139.5, 75.5); // .5 so it doesn't blur
[self.alertView addSubview:self.activityIndicatorView];
[self.activityIndicatorView startAnimating];
[self.alertView show];

稍后,如果登录失败,我想在警报 View 上放置“确定”按钮,而不关闭 self.alertView,并再次显示 self.alertView 的新实例。像这样的事情:

if (isThereErrorFromJsonResp) {
[self.activityIndicatorView stopAnimating];
[self.activityIndicatorView removeFromSuperview];
self.activityIndicatorView = nil;
[self.alertView setTitle:isThereErrorFromJsonResp];
//here i want to show ok button how?
return;
}

那么我应该如何放置 OK 按钮呢?有什么建议吗?

最佳答案

删除获取响应时的警报并像这样显示一个新的警报实例

[self.alertView dismissWithClickedButtonIndex:0 animated:YES];
self.alertView = [[UIAlertView alloc] initWithTitle:isThereErrorFromJsonResp
message:@"\n"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[self.alertview show];

解决方案

好的,试过了,明白了

使用

    [alertView dismissWithClickedButtonIndex:0 animated:YES];
[alertView addButtonWithTitle:@"Ok"];
[alertView show];

这会将按钮添加到警报 View

关于iphone - 在运行时在 UIAlertview ios 中添加确定按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16857802/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com