Reputation: 283
How to Stop Pushing segue when some condition is failed
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
internet *myclass = [[internet alloc]init];
if ([myclass connectedToInternet]) {
if ([[segue identifier] isEqualToString:@"showShoping"]) {
_pass = @"shop";
MyTabController *mvc = (MyTabController *)segue.destinationViewController;
mvc.myCategory = _pass;
}
if ([[segue identifier] isEqualToString:@"showTravel"]) {
_pass = @"travel";
MyTabController *mvc = (MyTabController *)segue.destinationViewController;
mvc.myCategory = _pass;
}
if ([[segue identifier] isEqualToString:@"showFood"]) {
_pass = @"food";
MyTabController *mvc = (MyTabController *)segue.destinationViewController;
mvc.myCategory = _pass;
}
else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"No Internet!"
message:@"No working internet connection is found."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
}
Thanks
Upvotes: 2
Views: 56
Reputation: 46
- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(nullable id)sender NS_AVAILABLE_IOS(6_0);
you can override this method, return No to stop perform segue when some condition happens.
for example
- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender {
if ([identifier isEqualToString:@"showShoping" ]) {
return NO;
}
return YES;
}
}
Upvotes: 2