我在调用 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;
}
那么我应该如何设置确定按钮呢? 有什么建议吗?
在获得响应时删除警报并显示这样的新警报实例
[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/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |