How to pass prepareForSegue: an object

后端 未结 10 2072
北荒
北荒 2020-11-21 11:18

I have many annotations in a mapview (with rightCalloutAccessory buttons). The button will perform a segue from this mapview to a tableview

10条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-21 11:39

    I've implemented a library with a category on UIViewController that simplifies this operation. Basically, you set the parameters you want to pass over in a NSDictionary associated to the UI item that is performing the segue. It works with manual segues too.

    For example, you can do

    [self performSegueWithIdentifier:@"yourIdentifier" parameters:@{@"customParam1":customValue1, @"customValue2":customValue2}];
    

    for a manual segue or create a button with a segue and use

    [button setSegueParameters:@{@"customParam1":customValue1, @"customValue2":customValue2}];
    

    If destination view controller is not key-value coding compliant for a key, nothing happens. It works with key-values too (useful for unwind segues). Check it out here https://github.com/stefanomondino/SMQuickSegue

提交回复
热议问题