![](/img/trans.png)
[英]How to dismiss the current ViewController and change to the new ViewController in Swift?
[英]How to dismiss and push new ViewController
在我的应用程序中有一个浮动按钮。 它的功能是从任何地方打开可用的屏幕。
情境
假设我有4个屏幕,并且在每个屏幕中它们都是浮动按钮。
1. Home Screen
2. Services Screen
3. Contact Screen
4. Events
现在,假设我已打开所有屏幕。 目前,我在“联系人屏幕”中,我想转到“服务”。
然后,我必须再次推送服务,从而创建“服务屏幕”的对象。 这就产生了一个问题,就好像用户将10次访问服务,然后将创建10个新对象一样。
如何实现这种情况?
我的代码:
if([sender tag]==1)
{
[push home];
}
else if([sender tag]==2)
{
[push services];
}
else if([sender tag]==3)
{
[push Contact];
}
else
{
[push events];
}
试试这个。
UIViewController *popViewController = //assign here Services Screen or what view you want to back
BOOL isExist = NO;
for (UIViewController *viewController in self.navigationController.viewControllers) {
if ([viewController isEqual:popViewController]) {
isExist = YES;//exist view controller. so you should not create a new one
[self.navigationController popViewControllerAnimated:YES];
}
}
if (isExist==NO) {//not exist view controller. so you should create a new one
[self.navigationController pushViewController:YourViewController animated:YES];
}
我更喜欢使用UITabBarController
。
@NSUser,很抱歉没有回答您的确切问题,但我建议您使用UIPageViewController
进行“托管”并一次显示一个内容视图控制器。 这是苹果公司的概念文件 ,其中包含基本说明和操作方法。 祝好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.