{"id":21990092,"url":"https://github.com/skyhacker2/storyboardfun","last_synced_at":"2025-03-23T03:16:56.320Z","repository":{"id":148897896,"uuid":"46989305","full_name":"skyhacker2/StoryboardFun","owner":"skyhacker2","description":"StoryboardFun","archived":false,"fork":false,"pushed_at":"2015-11-27T16:24:29.000Z","size":1719,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-28T08:53:27.955Z","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":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/skyhacker2.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":"2015-11-27T16:15:18.000Z","updated_at":"2015-11-27T16:16:53.000Z","dependencies_parsed_at":"2023-04-14T09:46:17.027Z","dependency_job_id":null,"html_url":"https://github.com/skyhacker2/StoryboardFun","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyhacker2%2FStoryboardFun","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyhacker2%2FStoryboardFun/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyhacker2%2FStoryboardFun/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/skyhacker2%2FStoryboardFun/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/skyhacker2","download_url":"https://codeload.github.com/skyhacker2/StoryboardFun/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245048278,"owners_count":20552483,"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":"2024-11-29T19:37:11.868Z","updated_at":"2025-03-23T03:16:56.301Z","avatar_url":"https://github.com/skyhacker2.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# iOS Unwind Segue\n\n使用Storyboard开发iOS程序的时候，使用segue可以非常方便地进行ViewController之间的跳转。\n\n通常从一个controller跳到另外一个controller，使用show(push) segue。像下面这样：\n\n![img](./img/屏幕快照 2015-11-27 下午11.54.29.png)\n\n图中是从A跳转到B，如果需要从B回到A，很简单的方法就是：\n\n```\n[self dismissViewController:self animation:YES];\n```\n\n如果在Storyboard上面实现回退的话，我第一次是这样的：\n\n![img](./img/屏幕快照 2015-11-28 上午12.01.50.png)\n\n扑街，然后我发现这样并不是返回，而是重新实例化了一个A。栈结构现在相当于是：ABA.\n\n如果再从A到B的话，反复几次的话就是这样：ABABABAB。\n\n惨，严重的内存泄露。\n\n这时候就需要用到`Unwind Segue`。\n\n1.在需要回到的ViewController定义一个方法，参数是`UIStoryboardSegue *`\n\n```\n#import \u003cUIKit/UIKit.h\u003e\n\n@interface ViewController : UIViewController\n\n- (IBAction)onUnwindSegue:(UIStoryboardSegue *)segue;\n\n@end\n```\n\n2.Control Drag 连线到`ViewController`上方的`Exit`的那个东东那里。\n\n![img](./img/屏幕快照 2015-11-28 上午12.09.28.png)\n\nOK 大功告成。\n\n这时候点击返回后，前面的ViewController的`dealloc`方法都会被调用了。\n\n[TestProject in Github](https://github.com/skyhacker2/StoryboardFun)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskyhacker2%2Fstoryboardfun","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fskyhacker2%2Fstoryboardfun","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fskyhacker2%2Fstoryboardfun/lists"}