Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

xcode - Unwind segue with Navigation back button

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.

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

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

I tried this in viewDidLoad to overrride the action, but it didnt work [self.navigationItem.backBarButtonItem setAction:@selector(unwindSegueAction:)];

Is it possible to unwind a push segue with the back button?

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:)];

I know there are answers for using protocol and delegates, but I am interested in using the Xcode4.5 unwind segue method

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...