iOS UINavigationController如何连续返回

2020-01-08  本文已影响0人  三岁就很乖

有A–> B –> C,正常返回上一界面

[self.navigationController popViewControllerAnimated:YES];

可以如果由C直接返回A的话,就需要用下面的方法

首先自定义backBarButtonItem

UIBarButtonItem *leftItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"icon_back_black"] style:UIBarButtonItemStylePlain target:self action:@selector(backAction)];
self.navigationItem.leftBarButtonItem = leftItem;

自定义backBarButtonItem参照:https://blog.csdn.net/wlaizff/article/details/51592105

NSInteger index=[[self.navigationController viewControllers]indexOfObject:self];
 [self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:index-2]animated:YES];
上一篇下一篇

猜你喜欢

热点阅读