-1

I have two screens. From first screen to next screen I was connect push segue in storyboard. Now in my second screen one alert will show with ok button. after pressing ok button i need to go to my first screen

Here is my code:

- (void)signup:(NSDictionary *)params {
    if (error)
    {
        [PCUtilities showAlertWithTitle:@"Oops" message:error.localizedDescription cancelButtonTitle:@"ok"];
    }
}

Inside one method I have UIAlert.

This below code I tried but not working!!

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
    if([title isEqualToString:@"ok"])
    {
        [self.navigationController pushViewController:[self.storyboard instantiateViewControllerWithIdentifier:@"AppMainNavController"] animated:YES];
    }
}

AppMainNavController = is my navigation controller story board id

Fabio Berger
  • 1,921
  • 2
  • 24
  • 29
  • 1
    `alertView` is deprecated now please use `UIAlertController` as mentioned here : [UIAlertView first deprecated IOS 9](http://stackoverflow.com/questions/32690086/uialertview-first-deprecated-ios-9) – Bista Jan 13 '16 at 06:54
  • 1
    Use button index instead comparing the strings (titles). – byJeevan Jan 13 '16 at 06:57

3 Answers3

1
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if  (buttonIndex==0)
    {
        [self.navigationController popViewControllerAnimated:YES];
    }
}
Pang
  • 9,564
  • 146
  • 81
  • 122
0

Just pop to previous view controller as below. It will pop to Previous View controller which u have pushed from.

        - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
        {
            NSString *title = [alertView buttonTitleAtIndex:buttonIndex];
            if([title isEqualToString:@"ok"])
            {
                [self.navigationController popViewControllerAnimated:YES];
            }
        }
Vidhyanand
  • 5,369
  • 4
  • 26
  • 59
  • U need to set delegate:self for UIAlertView inside method and also add UIALertViewDelegate to ur .h file – Vidhyanand Jan 13 '16 at 07:02
  • did't get you?? i added `uialertdelegate` in my .h.. And what to set delegate inside my ` - (void)signup:(NSDictionary *)params {` method ??/ – user5735383 Jan 13 '16 at 07:11
  • change as delegate:self instead of delegate:nil at ur alert view code inside method. – Vidhyanand Jan 13 '16 at 13:40
0

Use Button index instead of button title it will be difficult if the app has multiple languages. If you are using push segue then just dismiss current view controller, it will automatically go previous page weather there is Push segue or modal segue.

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if(buttonIndex == 0)
    {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
}
Jaimish
  • 629
  • 5
  • 15