2

Question was solved! See the code at the bottom.

I'd like to pass some data between 2 controllers. I have MainViewController class where GoogleMap is loaded. On click at custom info window for each GMap's marker I want to open new window with place details. My storyboard is: Storyboard

Segue was named: showPlaceDetails:

Segue

Several methods was written:

- (void) mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker {
    [self performSegueWithIdentifier:@"showPlaceDetails" sender: nil];
}

(I also tried to use sender: [marker snippet]).

My prepareForSegue method:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    if ([segue.identifier isEqualToString:@"showPlaceDetails"]) {
        //[[segue destinationViewController] setDelegate:self];
        PlaceDetailsViewController *destViewController = segue.destinationViewController;
        //Pass some data
    }
}

But I got the message: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (RelaxInKZViewController) has no segue with identifier 'showPlaceDetails''

I did these steps:

  1. Add New View Controller on storyboard.
  2. Add Objective-C Class called PlaceDetailsViewController.
  3. Change custom class of newly added VC to "PlaceDetailsViewController"
  4. Add that code
  5. Clear Simulator's data and clean project

And nothing. I hope you can help me :) Thx, Artem.


Mr_bem has adviced me to refuse segues and use pushViewController method. It's good!

UIStoryboard *iPhoneStoryboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
    PlaceDetailsViewController *destViewController = [iPhoneStoryboard instantiateViewControllerWithIdentifier:@"PlaceDetailsViewController"];
    destViewController.placeData = marker.placeData;
    [self.navigationController pushViewController:destViewController animated:NO];
Artem Z.
  • 1,243
  • 2
  • 14
  • 36

2 Answers2

3

You are using a Push segue, this can only be performed with a navigationController, like:

[self.navigationController performSegueWithIdentifier:@"showPlaceDetails" sender: nil];

Note you should have a navigation controller before your ViewController, the one that pushes.

Or if you want, you can change its type to Modal, everything should work great for you (Y)

UPDATE

Okay, here's what I propose, remove the segue, make the storyboardID of your PlaceDetailsViewController to PlaceDetailsViewController from the IB, and add this code instead

    - (void) mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker {
        PlaceDetailsViewController *destViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PlaceDetailsViewController"];
[self.navigationController pushViewController:destViewController animated:YES]
se
    }

THIS MUST WORK! LOL!

primehalo
  • 859
  • 1
  • 14
  • 26
Albara
  • 1,306
  • 8
  • 14
  • Did you add a navigationController to your storyBoard and then make RelaxInKZViewController its root view controller? If you did this, the code I provided should work.. Or just change the type of the segue to modal. And yes, what you are doing is correct, just a small mistake, once fixed, it should be awesome! – Albara Nov 25 '13 at 10:33
  • Hold on control key, then drag from the navigation controller, to your RelaxInKZViewController, then chose segue type 'Root controller'. And thats it, use the code provided in my answer and you should be good to go (Y) – Albara Nov 25 '13 at 10:50
  • Try to delete the '.navigationController' ? – Albara Nov 25 '13 at 10:59
  • Oh awesome! Actually its the same. You are just creating a segue programatically... Glad I helped :) – Albara Nov 25 '13 at 13:38
0

You need to embed your RelaxInKZViewController inside UINavigationController to use push segue. Select RelaxInKZViewController-> from the menu at the top select Editor->Embed In->Navigation Controller. I think that will solve your problem.

Suhit Patil
  • 11,748
  • 3
  • 50
  • 60
  • Error is still alive :( http://s18.postimg.org/eo85ky76h/2013_11_25_14_34_32.png - It's my storyboard now. – Artem Z. Nov 25 '13 at 10:35
  • try cleaning the project and run again also reset the simulator settings. – Suhit Patil Nov 25 '13 at 10:39
  • this link may help you http://stackoverflow.com/questions/11874200/nsinvalidargumentexception-receiver-has-no-segue-with-identifier – Suhit Patil Nov 25 '13 at 10:45
  • try removing the segue and add it again. or alternatively you use [self.navigationController pushViewController:animated:] method in the didTapInfoWindowOfMarker: method to push next viewcontroller, it doesn't require segue. – Suhit Patil Nov 25 '13 at 10:52