警报视图在8.4上没有解雇

时间:2015-09-03 09:00:15

标签: ios objective-c

情景
1)我开始编辑键盘来了。
2)然后我触摸按钮
3)在触摸按钮上我添加了AlertView,然后添加我已经辞职的第一响应者
4)单击AlertView OK按钮我弹出viewController
 5)弹出后,keyBoard出现在该屏幕上一段时间并解散 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];
     }      
 }

4 个答案:

答案 0 :(得分:1)

在这里你添加self这意味着你的导航堆栈调用相同的ViewController,请大多数选择no-1& 2

更改

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

进入

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

其他选择no-2

 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]

答案 1 :(得分:1)

你有两种选择 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;
        }
    }

答案 2 :(得分:0)

如果你需要在点击调用cancelSkipButtonTouchUpInside的按钮时关闭键盘:使用以下行:

[self.view endEditing:YES];

答案 3 :(得分:0)

我已经通过使用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];