[英]adding ok button at run time in UIAlertview ios
I call alert with progress indicator view while calling web services.i am having an alert view set up like this: 我在调用Web服务时用进度指示器视图调用警报。我的警报视图设置如下:
[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];
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: 稍后,如果登录失败,我想在警报视图上放置“确定”按钮,不关闭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;
}
So how should i put OK button? 那我应该怎么按OK按钮? 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];
SOLUTION 解
Ok tried out and got it 确定尝试了一下
Use 采用
[alertView dismissWithClickedButtonIndex:0 animated:YES];
[alertView addButtonWithTitle:@"Ok"];
[alertView show];
This will add the button to the alertview 这会将按钮添加到Alertview
Look at using ATMHud instead - this is a heads-up-display that you can modify while its showing, and can show, start, stop, spinners, add messages etc. When I used it I had a message say "Tap to Cancel", then when the login succeeded, showed a "Success!" 请改用ATMHud-这是一个平视显示器,可以在显示时进行修改,并且可以显示,开始,停止,旋转器,添加消息等。当我使用它时,我收到一条消息,说“轻按以取消” ,然后登录成功后,显示“成功!”。 for a second or so, then made it disappear.
一秒钟左右,然后使其消失。 This looks HUD looks very professional in the way it animates, and you have a lot of control over it too.
HUD的动画显示方式看起来非常专业,您对它也有很多控制权。
Try this code: 试试这个代码:
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"" message:@"Logout in offline mode may cause of data lose. Do you still want to logout?" delegate:self cancelButtonTitle:@"NO" otherButtonTitles:@"YES",nil];
alert.tag=11;
[alert show];
[self performSelector:@selector(go:) withObject:alert afterDelay:1.0];
-(void)go:(UIAlertView*)alert
{
UIButton *b = (UIButton*)[alert viewWithTag:1];
b.titleLabel.text = @"test";
}
you will have to add "OK" button initially. 您必须首先添加“确定”按钮。 And set its property as
Hidden = TRUE
. 并将其属性设置为
Hidden = TRUE
。 and in go method set it property Hidden = FALSE
并在go方法中将其属性设置为
Hidden = FALSE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.