{"id":29547974,"url":"https://github.com/cythb/unwindsegue","last_synced_at":"2025-07-17T20:43:52.179Z","repository":{"id":9740012,"uuid":"11701264","full_name":"cythb/UnwindSegue","owner":"cythb","description":"UnwindSegue学习项目","archived":false,"fork":false,"pushed_at":"2013-07-27T07:06:53.000Z","size":276,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2023-03-24T06:47:46.523Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"RallyTechServices/rally-iteration-health","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cythb.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-07-27T06:53:07.000Z","updated_at":"2015-04-28T02:50:06.000Z","dependencies_parsed_at":"2022-07-08T06:30:38.143Z","dependency_job_id":null,"html_url":"https://github.com/cythb/UnwindSegue","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"purl":"pkg:github/cythb/UnwindSegue","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cythb%2FUnwindSegue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cythb%2FUnwindSegue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cythb%2FUnwindSegue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cythb%2FUnwindSegue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cythb","download_url":"https://codeload.github.com/cythb/UnwindSegue/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cythb%2FUnwindSegue/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265660797,"owners_count":23807220,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-07-17T20:43:49.558Z","updated_at":"2025-07-17T20:43:52.165Z","avatar_url":"https://github.com/cythb.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Unwind Segue学习\n在iOS 6(Xcode 4.5)中，UIViewController引入了下面三个函数：\n\n\t- (BOOL)canPerformUnwindSegueAction:(SEL)action fromViewController:(UIViewController *)fromViewController withSender:(id)sender\n\t- (UIViewController *)viewControllerForUnwindSegueAction:(SEL)action fromViewController:(UIViewController *)fromViewController withSender:(id)sender\n\t- (UIStoryboardSegue *)segueForUnwindingToViewController:(UIViewController *)toViewController fromViewController:(UIViewController *)fromViewController identifier:(NSString *)identifier\n\t\n这三个函数，打开帮助文档一顿猛查之后。发现自己还是云里雾里。一夜的辗转反侧之后终于有眉目了。请客官继续往下看。\n\n## Unwind Segue是什么\n通读上面的3个函数之后，我们发现最关键的两个词是“Unwind Segue”。字面意思是“解开segue”。我们就拿UINavgationController来说。导航视图控制器可以通过push操作来增加子视图控制器，也可以通过pop来弹出视图控制器。增加视图控制器我们也可以通过segue来操作。那么相对于segue来说弹出视图控制器，我们使用什么呢？没错，就是unwind segue。我们可以使用unwind segue来弹出导航控制器的视图；关闭popover；dismissed模态视图控制器；通过你定制的方式关闭视图控制器。通过unwind segue不仅可以转换到前一个视图控制器，甚至可以跳过中间一系列的视图控制器直接转换到前面的某一个视图控制器。\n\n## 实战\n\n1. 新建一个工程UnwindSegue\n2. 新建一个导航控制器，三个子视图控制器(红－\u003e绿使用push segue; 绿-\u003e蓝使用代码弹出模态视图控制器)![storyboard结构](https://raw.github.com/cythb/UnwindSegue/master/images/unwind_segue.png)\n3. 分别建立RedViewController, GreenViewController, BlueViewController\n4. 在storyboard中设置好视图控制器的具体类;并给BlueViewController设置Storyboard ID为BlueViewController\n5. 在GreenViewController.m中拖出onModalBtnClicked:的IBAction\n6. 在onModalBtnClicked:实现弹出BlueViewController的代码\n7. 在RedViewController中实现- (IBAction)unwindSegue:(UIStoryboardSegue *)sender;\n8. 在BlueViewCOntroller中选中按钮，按住control拖动到底部的EXIT上，松开鼠标，选中unwindSegue: ![unwind action选择](https://raw.github.com/cythb/UnwindSegue/master/images/unwind_action_sel.png)\n9. 运行程序看一下吧。\n\n\n## 小结\n\n1. 需要在目标视图控制器中实现 - (IBAction)unwindSegue:(UIStoryboardSegue *)sender; IB中才能将按钮拖拽到Exit上面去。\n2. 在 - (IBAction)unwindSegue:(UIStoryboardSegue *)sender; 中通过segue可以取得源视图控制器，以便满足一些特别的需求。（例如根据不同的来源显示不同的内容。这个和preparSegue:有些类似）\n3. unwind segue是减少控制器。 segue是增加控制器。\n4. unwind segue的执行顺序：\n\t1. 目标控视图控制器的容器会调用 segueForUnwindingToViewController:fromViewController:identifier: 来创建一个segue\n\t2. 在目标控视图控制器执行unwindSegue:\n\t3. 执行segue\n\n\t","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcythb%2Funwindsegue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcythb%2Funwindsegue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcythb%2Funwindsegue/lists"}