查了網(wǎng)上很多例子都不能解決我的問題,網(wǎng)上一堆辣雞,然后查了一下資料和譚哥哥一起解決了問題。
去百度云盤看效果:
鏈接: https://pan.baidu.com/s/1Suyloq5g_2RL7HXNtvI0og 提取碼: r3k9 復(fù)制這段內(nèi)容后打開百度網(wǎng)盤手機(jī)App,操作更方便哦
問題:
A present B 之后,B 再 present ?C或者D 的時候,B就會被dismiss掉。
解決方案代碼:
1、加入這個變量記錄當(dāng)前B視圖
```
代碼塊
@property (nonatomic, strong) UIViewController *presentingVC;
```
2、在B中加入重寫:
-(void)dismissViewControllerAnimated:(BOOL)flag completion:(void(^)(void))completion
{
? ? if (self.presentedViewController)
? ? {
? ? ? ? if (self.presentingViewController) {
? ? ? ? ? ? self.presentingVC = self.presentingViewController;
? ? ? ? }
? ? ? ? [super dismissViewControllerAnimated:flag completion:completion];
? ? }
3、從B回到A代碼:
if (self.presentingVC) {
? ? ? ? ? [self.presentingVC dismissViewControllerAnimated:YES completion:nil];
? ? }else{
?? ? ? ? ? [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
? ? }
重點(diǎn)->知識點(diǎn)講解:
?self.presentedViewController 是 self.present 出來的 modalVC
?self.presentingViewController 是 super.present 出來的 modalVC