Receiver has no segue with identifier“***”

蓝咒 提交于 2019-12-11 02:32:54

问题


I encounter this problem for the first time. I checked similar problems on stack overflow, but none of the solutions can solve my issue so I have this posting.

Up to the present, I have two view controllers(let's say A and B) and I am trying to connect them with a segue with name "toB". When I run the program, Xcode told me Receiver(B) has no segue with identifier "toB".

I am pretty sure that the spellings of the identifierin the storyboard and in the code are exactly the same. And the line of the segue has connected the A view controller and B view controller.

But the storyboard IDs of the two view controllers are different. Is it the problem??

Hope someone could help me out. Thanks in advance!


SOLUTION

Thanks for @Amit Shelgaonkar's hint! In my case, moving the performSegueWithIdentifier to viewDidAppear still doesn't work, but moving it to applicationWillEnterForeground solves the problem!

I still don't know why it doesn't work in my case, because when I tried to develop a testing app and put the performSegueWithIdentifier in viewDidAppear, it works perfectly.


回答1:


you call performSegueWithIdentifier:sender: in the viewDidLoad. You can not dismiss a UIViewController that isn't presented yet. viewDidLoad has purely memory management functions, you can use it as (part of a) constructor. What may work, is to start a segue in viewDidAppear, however I would suggest to start with the view you want at the first time.




回答2:


What to check:
1. Segue between A and B, name of segue.
2. Code should look like this: [self performSegueWithIdentifier:@"toB" sender:self];
3. Check that your B view has custom class.
4. Try cleaning project and run again.




回答3:


Bit old but hope this helps as I was having the same issue. Having run through all the suggestions here, the issue turned out to be on my receiving view, in the class declaration for that view I had set it as ViewController and not a UIViewController.

e.g. I had this originally and is wrong

class viewB: ViewController{

and this is right

class viewB: UIViewController{


来源:https://stackoverflow.com/questions/31241877/receiver-has-no-segue-with-identifier

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!