20

Consider a view with a button. We can drag a connection from this button to some other view controller, create a segue in IB and we are happy. What if I need a segue that is performed upon some event, say, network progress, and that is unrelated to any user actions? For now I'm placing a button, drag a segue from this button, hide the button, assign an identifier to a segue and somewhere in the code i perform this segue. However, I think that placing a dummy button is not a right way. Possibly I'm missing something using storyboards, could you please help me to understand this?

anticyclope
  • 1,577
  • 1
  • 10
  • 26

2 Answers2

46

Create your segue by ctrl dragging from your view controller to your next view. Then to call your segue, call:

[self performSegueWithIdentifier: @"SegueToScene1" sender: self];

Make sure you give your segue a name in the storyboard.

theDuncs
  • 4,649
  • 4
  • 39
  • 63
Darren
  • 10,182
  • 20
  • 95
  • 162
  • 2
    Ctrl-dragging from the view controller to the next view was the missing piece, thanks! – zrslv Feb 04 '13 at 01:10
1

You can use performSegueWithIdentifier: method to force the transition to a new view, based on some criteria. When you call this, it will also automatically call prepareForSegue: (which is usually called when the storyboard is about to transition to a new view).

I wrote a post about controlling pushing views here which should cover most of what you're talking about.

Timmy
  • 4,098
  • 2
  • 14
  • 34
Simon
  • 8,981
  • 2
  • 26
  • 32