方法一:通過(guò)ViewController的屬性presentingViewController判斷當(dāng)前頁(yè)面是否是被present出的,來(lái)確定采用dismiss方法
- (void)backAction
{
if (self.presentingViewController)
{
[self dismissViewControllerAnimated:YES completion:nil];
}
else
{
[self.navigationController popViewControllerAnimated:YES];
}
方法二:通過(guò)NavgationController的屬性topViewController判斷當(dāng)前頁(yè)面是否是被push出的最上層頁(yè)面,來(lái)確定采用pop方法 - (void)backAction
{
if (self.navigationController.topViewController == self)
{
[self.navigationController popViewControllerAnimated:YES];
}
else
{
[self dismissViewControllerAnimated:YES completion:nil];
}
}
方法三:通過(guò)NavgationController的屬性viewcontrollers數(shù)組索引屹耐,來(lái)判斷當(dāng)前頁(yè)面是否是被push過(guò)少漆,來(lái)確定采用dismiss方法 - (void)backAction
{
if ([self.navigationController.viewControllers.firstObject isEqual:self])
{//當(dāng)前頁(yè)面尚未被Push過(guò)
[self dismissViewControllerAnimated:YES completion:nil];
}
else
{
[self.navigationController popViewControllerAnimated:YES];
}
}