Performing segue from another class

前端 未结 3 794
南方客
南方客 2021-01-16 11:12

I am trying to call performSegueWithIdentifier from different class which is NSObject class and I am receiving this error:

Terminating app due to uncaught exception

3条回答
  •  遥遥无期
    2021-01-16 11:18

    The error note says that "DerinlikToPali" was not found in StoryBoard.

    Go to your storyBoard, select the segue and check it's Attribute Inspector (menu View - Utilities - Show Attribute Inspector). Make sure the identifier is the same string you use at performSegueWithIdentifier.

    Update (after looking at SampleProject):

    • SampleClass *sample = [SampleClass alloc] should be "alloc init" in general, so you not only allocate memory, but also complete the full object initialization.
    • SampleClass methodToSegue() doesn't create ViewController object as you expected. First see above "alloc init", but in this case you need more (below). Otherwise you will NOT have a valid UIViewController object. Note that you got to first give it a name at storyBoard, so that you can create it (using that name). Alternative is to use XIB instead of storyBoard, in which case you use initWithNibName:bundle:

      ViewController *vc = [[UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil] instantiateViewControllerWithIdentifier:@"viewController"];

    • Biggest problem is logical and I hope it's only within this SampleProject: objectA is created, creates objectB, which creates objectA and calls it's method... except that objectA creation creates objectB again --> and we have a forever loop and something will crash.

    Anyway, my updated answer is that your object creation was not completed before you tried to trigger the segue. Especially "ViewController" was not yet an actual UIViewController defined at storyBoard and thus did not have the expected segue.

提交回复
热议问题