NSArray *viewcontrollers=self.navigationController.viewControllers;
if (viewcontrollers.count>1) { if ([viewcontrollers objectAtIndex:viewcontrollers.count-1]==self) { //push方式 [self.navigationController popViewControllerAnimated:YES]; } } else{ //present方式 [self.navigationController dismissViewControllerAnimated:YES completion:nil]; }
通过presentviewcontroller的方式显示的viewcontroller不会存入self.navigationController.viewControllers数组中。而通过push方式显示的viewcontroller会存在该数组的最后。