Question

To do advanced A/B testing, I want to be able to create segue based on a config file.

At launch, my app download a JSON file containing informations to create dynamically the parts of the main page.

For exemple, a JSON like following will create 2 buttons on the main view. The first one will be blue with the label "button1" and the second one will be red with the label "button2".

{
"elements":
    "0": {
        "type": "button",
        "label": "button1"
        "color": "blue"
    },
    "1": {
        "type": "button",
        "label": "button2"
        "color": "red"
    }
};

Now, I want to add in the JSON something like that : "goto": "OptionViewController" where the value of the goto key is the view displayed when clicking on the button.

I want to be able to add or remove buttons of the mainPage (I see how to do that) and to change the view linked to a button (this is my problem) remotely, simply by changing the downloaded JSON.

The problem is that for moving from a view to another, I don't only need the name of the new view, I need also the segue.

This post say that it's impossible to create segue programmatically.

The only solution I've found is for each view creating a segue to every other view but this very dirty.

Was it helpful?

Solution

If you are using Storyboard and if the view controller you want to segue to is defined in there, with an identifier of "OptionViewController", then you can do this:

UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@“Main” bundle:nil];
OptionViewController *ovc = [storyboard instantiateViewControllerWithIdentifier:@“OptionViewController”];

[self presentViewController:ovc
                   animated:YES 
                 completion:nil];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top