How to “cancel” a UIStoryBoardSegue

前端 未结 9 1833
小蘑菇
小蘑菇 2020-12-23 21:40

Does anyone know how to \"stop\" a segue transition conditionally:

My table view cells represent products which can be viewed in a drill-down \"detail\" view... or

9条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-23 21:48

    In your - (void)prepareForSegue:(UIStoryboardSegue*)segue sender:(id)sender; method, you could add some code such as:

    if ([[segue identifier] isEqualToString:@"DemoSegue"] && !self.canOpenDemo) {
        id *nc = [segue destinationViewController]; // UIViewController, UINavigationController, etc. (keeping "id" will return warning)
        [nc dismissModalViewControllerAnimated:NO];
    }
    

    And this will stop the view from opening, however I have not checked, but it seems like it will have already called your destination view controllers initialize function (again, I haven't checked in Xcode, so I'm not entirely sure).

提交回复
热议问题