ios - Firing a segue from a different view -


i have segue navigates firstviewcontroller secondviewcontroller. happens press of button. code button is

- (ibaction)segue:(id)sender { [self performseguewithidentifier:@"myidentifier" sender:self]; } 

this happens correctly when press button.

what trying fire method view. tried doing

firstviewcontroller fvc = [[firstviewcontroller alloc] init]; [fvc segue:nil]; 

when try this, error message, reciever has no segue identifier 'myidentifier'

how fire segue programatically view?

there few issues here, boil down couple of key points:

  • segues storyboard thing, view controllers "know" segues if they're instantiated storyboard.
  • a view controller must onscreen perform segue.
  • segues transitions 1 specific view controller specific view controller.

so, in snippet:

firstviewcontroller fvc = [[firstviewcontroller alloc] init]; [fvc segue:nil]; 

the first problem alloc-init-ing gives instance of firstviewcontroller doesn't know storyboard came from, doesn't know segues. (this alone fixed using [instantiateviewcontrollerwithidentifier:][1], doesn't solve whole problem.) second problem instance doesn't fit anywhere ui hierarchy -- hasn't been presented modal view controller, it's not top view controller in current navigation controller, it's not visible window's root view controller, etc. in order transition screen 1 view another, first view needs onscreen.

what sounds want transition what's onscreen target of segue. notion of storyboard segue isn't transition destination -- it's source, destination, , transition or relationship between them. if have different source view, need different segue. so, if have segue firstviewcontroller secondviewcontroller, , want make similar transition otherviewcontroller (assuming that's 1 onscreen now) secondviewcontroller, need make second segue connecting otherviewcontroller secondviewcontroller.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -