问题
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 identifier
in 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