ios '接收器(<ViewController>)没有标识符为'addSegue'的segue

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20715462/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 22:50:14  来源:igfitidea点击:

'Receiver (<ViewController>) has no segue with identifier 'addSegue'

iosobjective-ciphoneswiftuistoryboardsegue

提问by MicahKE

I have a navigation controller that has a segue links between them called "addSegue". When I click on the tableViewcell though the app crashes and I get the error below:

我有一个导航控制器,它们之间有一个名为“addSegue”的 segue 链接。当我点击tableView单元格时,虽然应用程序崩溃了,但出现以下错误:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver (<MSAddFriendsViewController: 0x98cc340>) has no segue with identifier 'addSegue'

I don't think that I have any issues with my code. Here is the method in which I have the line showSegueWithIdentifier:

我不认为我的代码有任何问题。这是我有这条线的方法showSegueWithIdentifier

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSMutableSet *selectedUsers = [NSMutableSet set];

[self.tableView deselectRowAtIndexPath:indexPath animated:NO];
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];


cell.accessoryType = UITableViewCellAccessoryCheckmark;
PFRelation *friendsRelation = [self.currentUser relationforKey:@"friendsRelation"];
PFUser *user = [self.allUsers objectAtIndex:indexPath.row];
[friendsRelation addObject:user];
[self.currentUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    if (error) {
        NSLog(@"Error %@ %@", error, [error userInfo]);

    }    }];

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

}

Here is a picture of my storyboard

这是我的故事板的图片

Here is an updated picture of my storyboard

这是我的故事板的更新图片

回答by ooxio

I had this same problem and actually my problem was that I was calling

我有同样的问题,实际上我的问题是我打电话

WRONG: [self.navigationController performSegueWithIdentifier:@"ShowVerify" sender:self];

instead of

代替

CORRECT: [self performSegueWithIdentifier:@"ShowVerify" sender:self];

so check that you are calling correct performSegueWithIdentifier method :)

所以检查你正在调用正确的 performSegueWithIdentifier 方法:)

回答by Anbu.Karthik

enter image description here

在此处输入图片说明

use segue identifier in Push Method and give the proper connection

if you are using Identifier, then call this line where u need

如果您正在使用Identifier,则在您需要的地方调用此行

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

Swift 2.X

斯威夫特 2.X

self.performSegueWithIdentifier("identifierName", sender: self)

Swift 3

斯威夫特 3

self.performSegue(withIdentifier: "identifierName", sender: self)


Regarding the new screen you have added that way. In that screen, when you're finished and want to remove it, it's just:

关于您以这种方式添加的新屏幕。在该屏幕中,当您完成并想要删除它时,它只是:

self.dismiss(animated: false, completion: nil)

回答by JKillian

Hard to say for sure, but some other people have had similar problems:

很难确定,但其他一些人也有类似的问题:

  • In this question, the asker instantiated the storyboard with initinstead of instantiateViewControllerWithIdentifierso the segue wasn't set up properly.

  • In this question, it was just something weird going on internally with xcode and the simulator, and running Product->Clean helped.

  • And of course, it's possible the segue name in the code doesn't match the segue name on the Storybord, but I'm guessing you've checked that a lot of times already!

  • 这个问题中,提问者用init而不是实例化了故事板 ,instantiateViewControllerWithIdentifier所以转场没有正确设置。

  • 这个问题中,xcode 和模拟器内部发生了一些奇怪的事情,运行 Product->Clean 有帮助。

  • 当然,代码中的 segue 名称可能与 Storybord 上的 segue 名称不匹配,但我猜你已经检查过很多次了!

回答by Vinay Krishna Gupta

Check whether UIKIT being or not in header file. I unknowingly made new VC a subclass of View Controller.

检查 UIKIT 是否在头文件中。我不知不觉地将新的 VC 变成了 View Controller 的子类。