Reputation: 1304
I have a simple application with a UICollectionViewController
that has been designed in Storyboard
. There is a single cell (UICollectionViewCell
) that I've designed in the UICollectionViewController
because it is dynamic.
My UICollectionViewController
is called Videos
and I have a custom subclass of UICollectionViewCell
called VideosCell
where I have an IBOutlet
from Storyboard
to a UILabel
. Videos
is populated using a NSArray
of Languages. Within Storyboard
, I also have 2 UITableViewControllers
; one called VideosFromVideoTab
and another called English Topics
. I have set up a segue
from the VideosCell
in Storyboard
to the LanguagesFromVideos
and then in prepareForSegue
, I have the following:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSIndexPath *indexPath = [self.videosTabCollectionView indexPathForCell:sender];
[self.videosTabCollectionView deselectItemAtIndexPath:indexPath animated:YES];
VideosTabCollectionCell *videosTabCell = (VideosTabCollectionCell *)[self.videosTabCollectionView cellForItemAtIndexPath:indexPath];
if ([segue.identifier isEqualToString:@"languagesFromVideoSegue"])
{
if ([videosTabCell.videosTabCellLabel.text isEqualToString:@"Chinese\n汉语"])
{
LanguageFromVideoTabTableViewController *lfvtvc = (LanguageFromVideoTabTableViewController*)segue.destinationViewController;
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Chinese Videos" ofType:@"txt"];
NSString *testString = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
NSArray *listOfVideos = [testString componentsSeparatedByString:@"\n"];
NSMutableArray *availableVideosToPass = [listOfVideos mutableCopy];
NSString *theSelectedLanguage = @"Chinese - 汉语";
[lfvtvc setAvailableVideos:availableVideosToPass];
[lfvtvc setSelectedLanguage:theSelectedLanguage];
}
Etc
So I am checking this segue identifier
and then checking the language of the label to see what happens. That works very well.
However, in my head, for the English language, instead of going to VideosFromVideoTab
, it's supposed to go to the English Topic UITableViewController
, so I thought I could set up another segue
with a different identifier
and then just check that in the prepareForSegue
.
Issue
However, in Storyboard
, whenever I set another segue
from the VideosCell
, it keeps only one. So if I had a segue
from the VideosCell
to the VideosFromVideosTab
UITableViewController
, it keeps that, but if I set another segue
from the VideosCell
to the English Topic UITableViewController
, it removes the first segue.
In a separate area of the app, I have a segue
from a single UITableViewCell
to two different UITableViewControllers
. Am I missing something obvious that's stopping me from doing this from the UICollectionViewCell
?
Any thoughts would be appreciated!
Upvotes: 0
Views: 46
Reputation: 1975
You do have to use push programmatically.
FirstViewController * controller = (FirstViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"FirstView"];
[controller setAvailableVideos:availableVideosToPass];
[controller setSelectedLanguage:theSelectedLanguage];
[self.navigationController pushViewController:controller animated:YES];
And for second
SecondViewController * controller = (SecondViewController *)[self.storyboard instantiateViewControllerWithIdentifier:@"SecondView"];
[self.navigationController pushViewController:controller animated:YES];
In such way you could send to number of ViewControllers depend on selected cell.
Upvotes: 1
Reputation: 86
If you need more than one segue from the cell, you have to set segues from ViewController to ViewController with different ID.
Then catch Cell select and in use
[self performSegueWithIdentifier:@"id1" sender:self];
or
[self performSegueWithIdentifier:@"id2" sender:self];
Upvotes: 0