我正在使用ECSliding我有这个问题!
在我的项目中有这个文件:
InitViewController (ECSlidingController)
FirstViewController (UIViewController)
SecondViewController (UIViewController)
LeftMenuViewController (UIViewController)
ThirdViewController (UIViewController)
我使用 InitView 将我的 FirstView 实例化为顶 View ,向右滑动打开 LeftMenu。 在 LeftMenu 中有 2 个按钮,一个按钮加载为 FirstView 的顶 View ,第二个按钮加载 SecondView。
在我的 First 和 SecondView 中,有一个相同的按钮,它加载 ThirdView 不是作为顶 View Controller ,而是作为新 View :
ThirdViewController *third = [self.storyboard
instantiateViewControllerWithIdentifier:@"Third"];
[self presentViewController:third animated:YES completion:nil];
在我的 ThirdView 中有 2 个按钮,一个按钮加载 FirstView,第二个按钮加载 SecondView。 由于 ThirdView 不是俯 View ,而是另一个 View ,因此我必须调用 ECSliding 来打开我的 FirstView 或 SecondView。 我使用 InitView 成功从 ThirdView 加载了 FirstView
InitialSlidingViewController *home = [self.storyboard
instantiateViewControllerWithIdentifier:@"Init"];
[self presentViewController:home animated:YES completion:nil];
但是如何从 ThirdView 加载 SecondView 呢? 我的问题基本上是如何在正常 View 之后加载使用 ECSliding 的内容。
最佳答案
从Third
开始,我们想要返回到滑动 View Controller 并更改顶 View Controller 。您当前正在使用此代码做什么:
InitialSlidingViewController *home = [self.storyboard instantiateViewControllerWithIdentifier:@"Init"];
[self presentViewController:home animated:YES completion:nil];
正在创建一个全新的滑动 View Controller 来显示。最终,通过这样做,您将耗尽内存,因为您将分配数百个呈现的 View ,但这些 View 永远不可见。
所以,我们想要做的是给 Third
一个属性:
@property (weak, nonatomic) ECSlidingViewController *slideController;
我们希望在呈现 Third
之前设置该属性:
ThirdViewController *third = [self.storyboard instantiateViewControllerWithIdentifier:@"Third"];
third.slideController = self.slidingViewController;
[self presentViewController:third animated:YES completion:nil];
现在,当按下第三个按钮之一时,我们可以说:“显示什么?我们可以直接关闭还是需要更改并关闭?”:
- (void)oneButtonPressed {
if ([self.slideController.topViewController isKindOfClass:[SecondViewController class]]) {
FirstViewController *first = [self.storyboard instantiateViewControllerWithIdentifier:@"First"];
self.slideController.topViewController = first;
}
[self dismissViewControllerAnimated:YES];
}
您需要为twoButtonPressed
编写相应的方法,然后就完成了。
对于您的新评论,您应该将其放入导航 Controller 中并显示,而不是显示第三个
。然后,当您需要显示第四和第五时,只需将它们插入导航 Controller 并再次弹出即可。如果需要,您还可以为他们提供对 slideController
的引用。
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController :third];
[self presentViewController:nav animated:YES completion:nil];
关于ios - 从普通 View Controller 打开 ECSlidingViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16615538/