0

I have two viewcontrollers mainVC and drop_downVC. I also have an object called JSONutils. The user will enter input into a textfield in the mainVC viewcontroller and methods are then used in the JSONutils to contact a RESTful api and a JSON object is then returned and parsed. I'd like to segue to the drop_downVC viewcontroller when the connectionDidFinishLoading method in JSONutils completes. Everything is working up to the point of trying to segue to the drop_downVC. From the research I've been doing it seems using the performSegueWithIdentifier is the way to go. So below is the code that I'm trying to implement in the connectionDidFinishLoading method in JSONutils.

//JSONutils.m
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{

//NSLog(@"Succeeded! Received %d bytes of data",[receivedData length]);
//NSLog(@"The receivedData is: %@", receivedData);

//JSON parsing code from here to

//here...

[self performSegueWithIdentifier:@"segue_drop_downVC" sender:self];

}//(void)connectionDidFinishLoading

the above code gives me the following error.

No visible @interface for 'JSONutils' declares the selector 'performSegueWithIdentifier:sender:'

I've googled this error but can't find anything that applies to my specific solution.

I created the segue and named the segue identifier appropriately (segue_drop_downVC) using this post.

I've also been putting the following code anywhere (JSONutils, mainVC) possible to see if that would change anything but it hasn't.

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{

//NSLog(@"The segue identifier is: %@", [segue identifier]);
//if ([[segue identifier] isEqualToString:@"YOUR_SEGUE_NAME_HERE"])

drop_downVC *nextViewController = [segue destinationViewController];
}

I don't have much experience programming in Objective-C but when I have I've used storyboard and segue to move between viewcontrollers. When I have used storyboard and segues I've "segued" when the user hit a button. I've never had to wait for data to come back and then navigated to the next viewcontroller. My plan is continue to put all of my JSON manipulating and parsing methods in the JSONutils files. So I'd like to keep those type of methods out of mainVC and drop_downVC. I've been doing research, trying different things but can't seem to get it. Any help or feedback is greatly appreciated! Thanks.

Community
  • 1
  • 1
user2743
  • 1,423
  • 3
  • 22
  • 34

2 Answers2

0

The performSegueWithIdentifier is a method of the UIViewController class, so if your JSONUtils class is not a subclass UIViewController, you cannot send that message to self. That's what the error says.

The same applies to prepareForSegue.

To solve your problem, there are several alternatives. Maybe the simplest one is to use delegates.

neutrino
  • 2,297
  • 4
  • 20
  • 28
  • I just ended up moving my JSONutils methods to the view controller and the [self performSegueWithIdentifier:@"segue_drop_downVC" sender:self] worked like a charm. Was the easiest solution. Thanks. – user2743 Dec 03 '13 at 16:39
0

You need to call performSegueWithIdentifier from your view controller, not JSONutils. I think the way to do this is to create a delegate protocol in JSONutils and have the MainVC set itself as delegate when it creates an instance of JSONutils. Call the delegate method from connectionDidFinishLoading:

rdelmar
  • 103,982
  • 12
  • 207
  • 218