本文介绍了在运行时在UIAlertview iOS中添加确定按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在调用Web服务时使用进度指示器视图调用警报.我正在这样设置警报视图:
I call alert with progress indicator view while calling web services.i am having an alert view set up like this:
[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];
稍后如果登录失败,我想在警报视图上放置确定"按钮,不关闭self.alertView,然后再次显示self.alertView的新实例.
Later if login fails I want to put "OK" button on alert view, withot dismissing self.alertView, and again showing new instance of self.alertView.Some thing like this:
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按钮?有什么建议吗?
So how should i put OK button?Any Suggestion?
推荐答案
删除获取响应的警报并显示新的警报实例
Remove the alert on getting the response and display an new instance of alert like this
[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];
这会将按钮添加到Alertview
This will add the button to the alertview
这篇关于在运行时在UIAlertview iOS中添加确定按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!