How to get a uinavigation bar back button to return to anthother view controller

前端 未结 5 1673
Happy的楠姐
Happy的楠姐 2021-01-16 04:00

How would I go about having a UINavigation controller navigate not to the previous view but the view before that. Basically I would like it to jump back 2 places instead of

5条回答
  •  伪装坚强ぢ
    2021-01-16 04:15

    Set:

    self.navigationItem.backBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStyleBordered target:self action:@selector(goBack)] autorelease];
    

    then create a method -goBack

    -(void)goBack
    {
       UIViewController *ctrl = [self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count - 2];
       [self.navigationController popToViewController:ctrl animated:YES];
    }
    

提交回复
热议问题