abdul haziq
abdul haziq

Reputation: 57

How can I go back to the previous view controller?

When user click "OK" button from UIAlertController popup, it will go back to the previous view controller.I got stuck how to that.Below this is my code.

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

      }

Upvotes: 1

Views: 693

Answers (1)

Dipankar Das
Dipankar Das

Reputation: 700

Try this -

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

Upvotes: 2

Related Questions