【问题标题】:Alert view not dismissing on 8.4警报视图不会在 8.4 上关闭
【发布时间】:2015-09-03 09:00:14
【问题描述】:

场景
1)我开始编辑键盘来了。
2)然后我触摸一个按钮
3) 在 botton touch 上我添加了 AlertView,在添加之前我已经辞职了第一响应者
4)点击 AlertView OK 按钮我弹出 viewController
5)弹出后,键盘会在该屏幕上出现一段时间并关闭。
6)它应该在同一个控制器上被解除,而不是在前一个控制器上

代码-

- (IBAction)cancelSkipButtonTouchUpInside:(id)sender {

  [self.textMobileNumber resignFirstResponder];
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:@"Entered number will not be saved" delegate:self cancelButtonTitle:nil otherButtonTitles: @"OK",@"Cancel", nil];
    alertView.tag = ktagYourNumberWillNotBeSaved;
    [alertView show];
    alertView = nil ;

}


- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
case ktagYourNumberWillNotBeSaved:
   {
    [self.navigationController popToViewController:self animated:YES];
     }      
 }

【问题讨论】:

  • 可能在您的根控制器中尝试过,否则请检查您的开关条件是否已统计,同时删除此行 alertView = nil ;
  • 先检查popToViewController是否被调用。
  • 将 popToViewController: 替换为 popViewControllerAnimated: - 任何结果?
  • 您是否缺少代码?因为你只有一个随机的 case 语句,它看起来像是 switch case 语句的一部分。请你分享你所有的代码。
  • 弹出到视图控制器没有问题。控制器弹出成功。问题是键盘没有隐藏

标签: ios objective-c


【解决方案1】:

在这里你被添加了self这意味着你的导航堆栈调用相同的ViewController,请尽量避免选择no- 1 & 2

改变

 [self.navigationController popToViewController:self animated:YES];

进入

   [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:1] animated:YES];

否则选择第二个

 for (UIViewController *vc in self.navigationController.viewControllers) {
   if ([vc isKindOfClass:[ViewController2 class]]) // ViewController2 --> call your view controller where you want to pop
 {
    [self.navigationController popToViewController:vc animated:YES];
}
}

其他选择3

[self.navigationController popViewControllerAnimated:YES]

【讨论】:

  • 对于简单地移动到上一个 viewController 使用 [self.navigationController popViewControllerAnimated:YES]
  • 你的答案也很好,等我修改我的答案,tanx Jaideep
  • 你能给出为什么你打负分的原因吗,我们不知道你在哪个场景下工作,所以我们随机提交我们的答案
  • 我在几秒前看到了它
  • 检查this
【解决方案2】:

你有两个选择
1)你可以改变

[self.navigationController popToViewController:self animated:YES];    

进入

[self.navigationController popViewControllerAnimated:YES];

2)

for (UIViewController *controller in self.navigationController.viewControllers) {

        if ([controller isKindOfClass:[ViewController class]]) {

            [self.navigationController popToViewController:controller
                                                  animated:YES];
            break;
        }
    }

【讨论】:

    【解决方案3】:

    如果您只需在点击调用 cancelSkipButtonTouchUpInside 的按钮时关闭键盘:请在里面使用以下行:

    [self.view endEditing:YES];
    

    【讨论】:

    • @RKP 是你在 self.view 中的 UITextField 吗?
    【解决方案4】:

    我已经通过使用 UIAlertController 而不是 UIAlertView 解决了这个问题,因为它已被 iOS 8 弃用

     UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
    
        UIAlertAction *alertActionOk = [UIAlertAction actionWithTitle:NSLocalizedString(@"Ok", @"Ok action") style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            [self.navigationController popToViewController:self animated:YES];
        }];
        UIAlertAction *alertActionCancel = [UIAlertAction actionWithTitle:NSLocalizedString(CANCEL_ALERT_BUTTON, @"Cancel action") style:UIAlertActionStyleDefault handler:nil];
    
        }
        [alertController addAction:alertActionOk];
        [alertController addAction:alertActionCancel];
    
        [self presentViewController:alertController animated:YES completion:nil];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-02
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-24
      相关资源
      最近更新 更多