iphone - 单击警报 View 中的按钮时如何关闭警报 View

标签 iphone objective-c ios

我是 iOS 新手。

我正在研究警报 View 。这是我的代码。这里有 2 个警报 View :登录页面的 successfulallertunsuccessfulallert。我在这里也使用alertview delegate,它适用于两个alertview,但我只想为成功的alertview工作,并且导航应该只为成功的alertview完成。如果有人知道这一点请帮助我。

NSString *responseOfResult = [[NSString alloc]initWithString:[result response]];
    NSRange match;
    //  NSLog(@"string= %@", str);
    match = [responseOfResult rangeOfString: @"successful"];
    if(match.location == NSNotFound)
    {
        UIAlertView *unsuccessfulAllert = [[UIAlertView alloc]
                               initWithTitle:@"Alert"
                               message:responseOfResult
                               delegate:self
                               cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
        [unsuccessfulAllert show];

    }
    else {
        UIAlertView *successfulAllert = [[UIAlertView alloc]
                               initWithTitle:@"Message" message:@"Login successful." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
        [successfulAllert show];
     }
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if(buttonIndex == 0){
        [[self navigationController]pushViewController:registerUserScreen animated:YES];
    }
}

最佳答案

为什么不将“OK”作为cancelButtonTitle?一切都会自动处理。

UIAlertView *successfulAllert = [[UIAlertView alloc]
                               initWithTitle:@"Message" message:@"Login successful." delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
        [successfulAllert show];

关于iphone - 单击警报 View 中的按钮时如何关闭警报 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10547821/

相关文章:

iphone - 如何将 UILocatNotification 设置为每天早上 9 点触发

iphone - UIWindow 在哪里实例化,storyboard 传入?

ios - 将动态文本 GPUImage 添加到过滤后的视频

ios - 带有 iOS8 的 iPod Touch 被检测为 iPhone

ios - UIView 在 iPhone 上显示完美,但在 iPad 上显示不完美

iphone - UITableViewCell 中的 UIButton

iphone - setStatusBarOrientation问题

ios - UITextField secureTextEntry 是否关闭 autocorrectionType 和 autocapatilizationType?

ios - XIB TableViewCell 未调整大小以适应宽度

iphone - 垂直 slider 只有一个方向