简体   繁体   中英

unwind doesn't work

iOS 8.1

xCode 6.1.1

My storyboard is: Tab Bar Controller -> Navigation Controller (NC) 1 -> ViewController(VC) 1 -> NC2 -> VC2 -> NC3 -> VC3

From VC2 to NC3 is Show details segue. I have a Cancel button in VC3 that is supposed to unwind to NC2/VC2.

I already add the unwind method to the header and swift files of Custom Class of both NC2 and VC2 and Ctrl+drag from Cancel button to VC3 exit.

I also tried Ctrl-drag to NC3 exit or NC2 exit

Nothing happen. Any thought? Workaround?

Already looked into Unwind Segue in Xcode 6.1.1 with storyboard and Unwind Segue not working in iOS 8 but don't see if I miss anything.

EDIT Add println statement into the unwind method but nothing printed so the method is not call. Header file code of VC2:

#ifndef SettingsViewController_h
#define SettingsViewController_h

#endif

@interface SettingsViewController (Workaround)
- (IBAction)unwindToSettings: (UIStoryboardSegue *)segue;
@end

swift code portion of VC2

@objc(SettingsViewController) class SettingsViewController: UITableViewController{
  @IBAction func unwindToSettings(segue:UIStoryboardSegue){
        println("unwind")
  }
}

My unwind segues work just fine. Coming back from VC3, your code in VC2 should look something like this:

@IBAction func didFinishWithVC3(segue: UIStoryboardSegue) { 
    let controller = segue.sourceViewController as VC3 
    someVariableInVC2 = controller.someVariableInVC3 // If you need to get data from VC3 to VC2
}

Note that you need the segue: UIStoryboardSegue parameter.

Then just control-drag from your Cancel button in VC3 to the Exit icon above VC3 in your storyboard and select "didFinishWithVC3".

I created a dummy project with the same structure: Tab Bar Controller followed by Navigation Controller and it doesn't work so I suspect it has something to do with Tab Bar Controller and the structure of the Controllers.

End up using Present Modally segue and

dismissViewControllerAnimated(true, completion: nil)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM