Reputation: 7360
I have a UINavigationController
that has a UITableview
loaded in it. Inside this UITableView
I have one prototype
cell and I reused it a few times with static data that never changes and never will. So, I connected two push segues from the viewControlller
it self to two their destination
view controllers. This seemed to work just fine. To invoke these segues
, I used UItableViews
delegate method: didSelectRowAtIndexPath
so I know which row was tapped and then, go to the correct viewController
.
No, problem, it works.
I then added a third viewController
and its accompanying, segue
to match, same as the previous two and same setup in didSelectRowAtIndexPath
- now, when I tap the second cell, that was working, didSelectRowAtIndexPath
is called as expected, then it called the correct segue, then prepareForSegue
is called. Then, prepareForSegue
is called again (at this point, didSelectRowAtIndexPath
has not been called again) the prepareForSegue
method then invokes the incorrect segue (The third segue I added).
I cannot figure out who is calling the prepareForSegue
method for the second time and why its got the wrong identifier.
Is there something I am doing wrong?
Some code samples
Here is the didSelectRowAtIndexPath
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
switch (indexPath.row)
{
case CategoryFilter:
{
[self performSegueWithIdentifier:@"FilteredCategoryView" sender:self];
break;
}
case PriceFilter:
{
[self performSegueWithIdentifier:@"FilterByPriceSegue" sender:self];
}
case ConditionFilter:
{
[self performSegueWithIdentifier:@"SearchFilterConditionSegue" sender:self];
}
}
}
Then in the prepareForSegue
method:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"FilteredCategoryView"]){
//No data to pass just yet
}
if ([segue.identifier isEqualToString:@"FilterByPriceSegue"]){
//No data to pass just yet
}
if ([segue.identifier isEqualToString:@"SearchFilterConditionSegue"]){
//No data to pass just yet
}
}
In the above method - I am not passing data just yet, but I will. Its this method that gets called twice.
Upvotes: 1
Views: 2337
Reputation: 2771
You forgot the break
in the second and third case of your switch
maybe it will help ;)
Change your switch with :
switch (indexPath.row)
{
case CategoryFilter:
{
[self performSegueWithIdentifier:@"FilteredCategoryView" sender:self];
break;
}
case PriceFilter:
{
[self performSegueWithIdentifier:@"FilterByPriceSegue" sender:self];
break;
}
case ConditionFilter:
{
[self performSegueWithIdentifier:@"SearchFilterConditionSegue" sender:self];
break;
}
}
If you don't put the break
instruction in each of your cases the switch will do all the other case until the end of the switch or another break
instruction.
Upvotes: 4