使用导航后退按钮放松 segue [英] Unwind segue with Navigation back button
问题描述
我已经观看了有关故事板实现的 Apple 演示视频,其中包含 unwind segues 部分,并在主视图上观看了使用自定义按钮的演示.效果很好.
I have watched the apple demo video on storyboard implementation with the unwind segues section and seen the demo using custom buttons on the main view. That works fine.
我也在这里看到了一个很好的例子,它也同样有效.http://www.techotopia.com/index.php/Using_Xcode_Storyboarding_%28iOS_6%29#Unwinding_Storyboard_Segues/a>
I have also seen a good example of the same thing here which works also. http://www.techotopia.com/index.php/Using_Xcode_Storyboarding_%28iOS_6%29#Unwinding_Storyboard_Segues
但是,我希望有一个从父级(带有主表单数据)到子级(带有高级设置选项)的正常推送segue,然后使用导航栏中的后退按钮而不是使用视图上的自定义按钮,如演示中所示.当父控制器上的另一个保存按钮被按下时,父控制器会将所有内容保存到 API 服务器.
However, I wish to have a normal push segue passing from parent (with main form data) to child (with advanced settings options) and then return to the parent view controller using the back button in the navigation bar rather than with a custom button on the view as shown in the demo. The parent controller will then save everything to an API server when a further save button on the parent controller is pressed.
我似乎无法覆盖导航后退按钮以将其指向我的展开转场操作,并且由于故事板上没有出现后退按钮,我无法将绿色退出按钮拖到它
I dont seem to be able to override the navigation back button to point it down to my unwind segue action and since the back button doesnt appear on the storyboard, I cant drag the green Exit button to it
我在 viewDidLoad 中尝试了这个来覆盖操作,但它没有用[self.navigationItem.backBarButtonItem setAction:@selector(unwindSegueAction:)];
I tried this in viewDidLoad to overrride the action, but it didnt work [self.navigationItem.backBarButtonItem setAction:@selector(unwindSegueAction:)];
是否可以使用后退按钮来解除 push segue?
Is it possible to unwind a push segue with the back button?
到目前为止,我最好的想法是从 viewDidLoad 方法中覆盖后退按钮,但这消除了有角度的后退按钮样式,而且似乎是对简单问题的粗略解决
The best idea I had so far was to override the back button from the viewDidLoad method, but that removes the angled back button style and also seems like a rough hack to a simple problem
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"back" style:UIBarButtonItemStyleBordered target:self action:@selector(unwindSegue:)];
我知道有使用协议和委托的答案,但我对使用 Xcode4.5 unwind segue 方法很感兴趣
I know there are answers for using protocol and delegates, but I am interested in using the Xcode4.5 unwind segue method
推荐答案
最后我不需要展开 segue,因为我仍然可以通过跟随导航控制器获得对父控制器方法的引用.
In the end I didn't need to unwind the segue since I could still get a reference to the parent controller methods by following the navigation controller.
通过在子控制器的 - (void)viewWillDisappear:(BOOL)animated
方法中执行以下操作,我能够获得参考
I was able to get a reference by doing the following in the - (void)viewWillDisappear:(BOOL)animated
method of the child controller
NSInteger currentVCIndex = [self.navigationController.viewControllers indexOfObject:self.navigationController.topViewController];
FirstViewController *parent = (FirstViewController *)[self.navigationController.viewControllers objectAtIndex:currentVCIndex];
parent.barcodeType = indexPath.row;
将设置变量完美地传递回原始控制器.
which passed the settings variable back to the original controller perfectly.
我还在子控制器顶部添加了对父控制器的导入引用
I also added an import reference to the parent controller at the top of the childcontroller
这篇关于使用导航后退按钮放松 segue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!