2

我在调用 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];

稍后,如果登录失败,我想在警报视图上放置“确定”按钮,而不关闭 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按钮呢?有什么建议吗?

4

3 回答 3

4

在获得响应时删除警报并显示一个新的警报实例,如下所示

[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];

这会将按钮添加到警报视图

于 2013-05-31T12:57:38.037 回答
1

看看使用ATMHud - 这是一个平视显示器,您可以在显示时对其进行修改,并且可以显示、启动、停止、微调器、添加消息等。当我使用它时,我有一条消息说“点击取消” ,然后当登录成功时,显示“Success!” 一秒钟左右,然后让它消失。这看起来 HUD 在动画方式上看起来非常专业,而且您也可以对其进行大量控制。

于 2013-05-31T13:01:45.947 回答
-1

试试这个代码:

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

}

您最初必须添加“确定”按钮。并将其属性设置为Hidden = TRUE。并在 go 方法中设置它的属性Hidden = FALSE

于 2013-05-31T14:11:25.003 回答