0

I just build a class to manage correctly my database and JSON request. The problem is that now, how can I perform the segue ?

Here is my code In my view :

- (IBAction)loginClick:(id)sender
{
    NSString *post = [NSString stringWithFormat:@"username=test&password=test"];
    [[DataManagement sharedManager] WebServiceLogin:post];
}
- (void) showTypeView
{
    [self performSegueWithIdentifier:@"showTypeView" sender:nil];
}

In my class :

    -(void)connectionDidFinishLoading:(NSURLConnection *)connection
    {
...
                switch ([[response valueForKey:@"success"] intValue])
                {
                    case 0:
                    {
                        NSLog(@"error: %@ error Description: %@", [response valueForKey:@"success"], [response valueForKey:@"error_message"]);
                        break;
                    }
                    case 1:
                    {
                        LoginViewController *showView = [LoginViewController new];
                        [showView showTypeView];
                        break;
                    }
                    default:
                        break;
                }
...
    }

When I launch, I have an error : **

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<LoginViewController: 0x165afd30>) has no segue with identifier 'showTypeView''
*** First throw call stack:
(0x2592e2eb 0x250fadff 0x29e2b037 0xe1819 0xdb64f 0x25f64de1 0x25f64d99 0x25f64e8d 0x25e261ef 0x25edf04f 0xa77cab 0xa7f835 0x25e171e3 0x258415f9 0x25e170cb 0x25e16f95 0x25e16e29 0x258f1257 0x258f0e47 0x258ef1af 0x25841bb9 0x258419ad 0x26abbaf9 0x29b2dfb5 0xe3ea9 0x254f4873)
libc++abi.dylib: terminating with uncaught exception of type NSException

**

2
  • 1
    You can use a (custom) delegate (in LoginViewController) to tell the parent class that it needs to perform the segue.
    – Larme
    May 9, 2016 at 16:01
  • How Can I do that :) I am a newbie. I am looking for that
    – ΩlostA
    May 9, 2016 at 16:23

1 Answer 1

1

If you're using segueWithIdentifier then you need to already have the segue built in Storyboard and labeled correctly as "showTypeView". Otherwise you should use a navigation controller to push a view controller or use self presentViewController to show a modal view controller.

EDIT: Building off of Larme's comment, you can build a delegate like this:

// In your class.h file
@property (weak, nonatomic)id<SegueDelegate> delegate;

// In class.m file
LoginViewController *showView = [LoginViewController new];
self.delegate = showView;
[self.delegate segue];


// In LoginViewController.h
@protocol SegueDelegate
-(void)segue;
@end

@interface LoginViewController: UIViewController <SegueDelegate>
-(void)segue;
@end

// In LoginViewController.m
@implementation LoginViewController
-(void)segue
{
    [self performSegueWithIdentifier:@"showTypeView" sender:nil];
}
@end
1
  • That's what I did, but it doesn't work. If I use the same function directly in the viewcontroller, it works.
    – ΩlostA
    May 9, 2016 at 16:22

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.