其实也就是找你的上几层控制器
for (UIViewController *controller in self.navigationController.viewControllers) {
//PhotoEssayViewController就是你的不同的控制器,判断是哪个控制器跳转到当前页面的
if ([controller isKindOfClass:[PhotoEssayViewController class]]) {
//此处写操作代码
PhotoEssayViewController *photosVC =(PhotoEssayViewController *)controller;
photosVC.str = self.str;
[self.navigationController popToViewController:photosVC animated:YES];
}
//VideoEssayViewController则是另外一个控制器,
else if ([controller isKindOfClass:[VideoEssayViewController class]]) {
//此处写操作代码
VideoEssayViewController *videoVC = (VideoEssayViewController *)controller;
videoVC.str = self.str;
}
}
第二种,则是通过navigationController.viewControllers的数组来找
//self.navigationController.viewControllers.count-2
是你当前控制器的上层控制器
if ([[self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-2] isKindOfClass:[MySelfTableViewController class]]) {
MySelfTableViewController *myselfVC = [self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-2];
//找到之后进行操作咯
UILabel *currentCity = [myselfVC.view viewWithTag:3004];
currentCity.text = self.provinceStr;
[self.navigationController popToViewController:myselfVC animated:YES];
}