Does anyone know how to \"stop\" a segue transition conditionally:
My table view cells represent products which can be viewed in a drill-down \"detail\" view... or
Here another solution I just found.
In your Mainstoryboard TableView, as you use automatic segue from your cell (identifier=Cell) to the destination view, you can also add another cell with another identifier (identifier=CellWithoutSegue). So when creating new cell in cellForRowAtIndexPath, just reuse the cell identifier you want (with or without segue).
Hope it helps!
(Tell me if you want some code source examples).
Regards,
If you are targeting iOS 6 or greater, then my knowledge of the cleanest way to do this is the following:
-(BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
{
if([identifier isEqualToString:@"show"])
{
NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
Blocco *blocco = [self.fetchedResultsController objectAtIndexPath:selectedRowIndex];
return [blocco meetRequiredConditions];
}
return YES;
}
Where there is a method
-(BOOL) meetsRequiredConditions;
Defined on your Blocco class returns YES if the "couple of things" which permit a drill-down are valid.
The easiest solution is to create manual segue in story board and use that as seen below.
[self performSegueWithIdentifier:@"loginSuccessSegue" sender:self];
Or
@Fabio: I was trying to get a solution for same kind of use-cases and I almost found a solution.
Use-cases 1. Stop segue transition conditionally 2. Change destination viewController conditionally
Solution:
Use "Custom" segue. Follow below steps to create Custom segue 1. Create a subclass of UIStoryboardSegue "MyCustomSegue.h"
@interface MyCustomSegue : UIStoryboardSegue
@end
"MyCustomSegue.m"
Override initWithIdentifier for implementing use-case 1 and 2 If you return nil, segue will be cancelled/no action will be taken You instantiate your ViewController and set that as a destination. You can set destination as your old xib file also.. that code is commented, but I ensured that will work.
@implementation MyCustomSegue
- (id)initWithIdentifier:(NSString *)identifier source:(UIViewController *)source destination:(UIViewController *)destination{
UIStoryboard *storyBoard= [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
UIViewController *viewController = [storyBoard instantiateViewControllerWithIdentifier:@"testIdentifier"];
// MyViewController* viewController= [[MyViewController alloc]initWithNibName:@"MyViewController" bundle:nil];
return [super initWithIdentifier:identifier source:source destination:viewController];
}
You can implement use-case 1 here also..
- (void)perform {
// if either source or destination is nil, stop
if (nil == self.sourceViewController || nil == self.destinationViewController) return;
// return; //No Action. Segue will be cancelled
UINavigationController *ctrl = [self.sourceViewController navigationController];
[ctrl
pushViewController:self.destinationViewController
animated:YES];
}
Hope this helps. Plz write if you are not clear.