如何返回上一个视图控制器?

时间:2017-04-06 07:34:44

标签: objective-c uialertcontroller uialertaction

当用户点击UIAlertController弹出窗口中的“确定”按钮时,它将返回上一个视图控制器。我遇到了问题。请告诉我这是我的代码。

if (jsonData == nil){
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Error!" message:@"This Git repository is empty" preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
    [alertController addAction:ok];

    [self presentViewController:alertController animated:YES completion:nil];

      }

1 个答案:

答案 0 :(得分:2)

试试这个 -

if (jsonData == nil){
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Error!" message:@"This Git repository is empty" preferredStyle:UIAlertControllerStyleAlert];

        UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action){
            // Ok action example
            [self.navigationController popViewControllerAnimated:YES];
        }];
        [alertController addAction:ok];

        [self presentViewController:alertController animated:YES completion:nil];
    }