Pergunta

I'm using a storyboard. Let's say I have a view controller that's named MYviewController.

In - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender; I would like to substitute the view controller that I'm segueing to, by one of its child, for example: MYviewControllerChild1 OR MYviewControllerChild2. The child that's segued to depends on the sender parameter.

These view controllers have the same scene (in the storyboard). Only their behaviour is slightly different.

I have a tableView that shows the user the settings of the application. When he clicks a cell, it segues to a viewController where he can modify the value of some setting. Some of theses are alphanumeric, others are numeric. Depending on which cell is clicked, I'd like the input viewController to format the value accordingly (if it's a decimal value I'll use a NSNumberFormatter for example).

Is that possible?

Foi útil?

Solução

As mentioned in comments to your OP, I believe you should handle this kind of scenario in one viewcontroller.

However, if you insist on using separate controllers, maybe because you think the functionality will be expanded later down the line and therefore add more diversity, you need to handle this by creating multiple storyboard scenes - one for each child controller.

The destination view controller in prepareForSegue is imposed by the viewcontroller at the end of the segue in the storyboard. I don't think there is any way to override that.

Outras dicas

As described, your problem isn't really a good candidate for a storyboard. If you use a storyboard you will have to create and sync multiple scenes. Several possible solutions::

  1. Create multiple storyboard scenes and invoke them manually via performSegueWithIdentifier.

  2. Use a nib file instead of a storyboard for this scene. You can use a single nib file since the view controller is created outside the storyboard with [[VCClass alloc] initWithNibFile: bundle: You can create the appropriate view controller class and pass the same nib file to all instances.

  3. Use a single storyboard scene and view controller and pass in typing information in your prepareForSegue.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top