Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XCode Storyboard: how to create a segue when the segue trigger is not on storyboard

So I started playing with storyboards in XCode 4.3.2. I started with the Master-Detail application (split view application for iPad). In the detail view (named DetailVC) I have a view where I displayed an array of custom views.

The custom views (named GridView) have a tap gesture recognizer which is supposed to handle the tap event on each custom view. Tapping a GridView pushes a view controller show some search results (named SearchResultsVC).

With GridView created in a separate nib file, and the DetailVC and SearchResultsVC reside in storyboard, how can I create a push segue with destination SearchResultsVC? I just created a segue between DetailVC and SearchResultsVC? Is there someway I can trigger this segue programatically from inside the GridView class when tap gesture is recognized????

like image 481
vikmalhotra Avatar asked May 08 '12 03:05

vikmalhotra


1 Answers

In the method where you handle the tap use:

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

In your StoryBoard control drag from your DetailVC to your SearchResultVC and choose what type of segue you would like. Make sure to name your segue identifier the same as the one in the method above in attributes inspector.

I'm gonna try and improve my answer I messed it up I think:

1) In your DetailVC.h create an instance variable for your GridView like this

IBOutlet UIView * gridView;

also create a getter method and an IBAction for your grid view like this

-(UIView *)gridView;
-(IBAction)myGridGotPressed:(id)sender;

2)Now in your DetailVC.m implement your methods like this

-(UIView *)gridView{
if(!gridView){
[[NSBundle mainBundle] loadNibNamed:@"GridView" owner:self options:nil];
}
return gridView;
}

Also implement your IBAction like this

-(IBAction)myGridGotPressed:(id)sender{
[self performSegueWithIdentifier:@"yourSegueIdentifier" sender:self];
}

3) To make this work you need to change the filesOwner class of your GridView to DetailVC and then hook up the outlets and Actions as normal.

I hope that helps.

like image 131
Gaz Long Avatar answered Oct 14 '22 06:10

Gaz Long