而不是push segue如何替换视图控制器(或从导航堆栈中删除)? [英] Instead of push segue how to replace view controller (or remove from navigation stack)?

查看:182
本文介绍了而不是push segue如何替换视图控制器(或从导航堆栈中删除)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有并且可以1)替换视图而不是推送2)删除导航堆栈中不需要的视图。



如何在本机应用程序中执行相同操作?

解决方案

你可以使用自定义segue:要做到这一点,你需要创建一个子类UIStoryboardSegue(示例MyCustomSegue),然后你可以用这样的东西覆盖perform

   - (void)执行{
UIViewController * sourceViewController =(UIViewController *)[self sourceViewController];
UIViewController * destinationController =(UIViewController *)[self destinationViewController];
UINavigationController * navigationController = sourceViewController.navigationController;
//在推送
之前弹出到根视图控制器(非动画)[navigationController popToRootViewControllerAnimated:NO];
[navigationController pushViewController:destinationController animated:YES];
}

此时转到Interface Builder,选择customsegue,然后放入你的班级名称(例如MyCustomSegue)


I have a small iPhone app, which uses a navigation controller to display 3 views (here fullscreen):

First it displays a list of social networks (Facebook, Google+, etc.):

Then it displays an OAuth dialog asking for credentials:

And (after that, in same UIWebView) for permissions:

Finally it displays the last view controller with user details (in the real app this will be the menu, where the multiplayer game can be started):

This all works well, but I have a problem, when the user wants to go back and select another social network:

The user touches the back button and instead of being displayed the first view, is displayed the second one, asking for OAuth credentials/permissions again.

What can I do here? Xcode 5.0.2 shows a very limited choice for segues - push, modal (which I can't use, because it obscures navigation bar needed for my game) and custom.

I am an iOS programming newbie, but earlier I have developed an Adobe AIR mobile app and there it was possible to 1) replace view instead of pushing and 2) remove an unneeded view from navigation stack.

How to do the same in a native app please?

解决方案

You could use a custom segue: to do it you need to create a class subclassing UIStoryboardSegue (example MyCustomSegue), and then you can override the "perform" with something like this

-(void)perform {
    UIViewController *sourceViewController = (UIViewController*)[self sourceViewController];
    UIViewController *destinationController = (UIViewController*)[self destinationViewController];
    UINavigationController *navigationController = sourceViewController.navigationController;
    // Pop to root view controller (not animated) before pushing
    [navigationController popToRootViewControllerAnimated:NO];
    [navigationController pushViewController:destinationController animated:YES];    
}

At this point go to Interface Builder, select "custom" segue, and put the name of your class (example MyCustomSegue)

这篇关于而不是push segue如何替换视图控制器(或从导航堆栈中删除)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆