接收器(<ViewController>)没有名为“addSegue”的连线。

11

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

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

我认为我的代码没有任何问题。这是我使用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];

}

这里是我的故事板图片。

这里是我更新后的故事板图片。


请检查您在Storyboard中设置的Segue标识符。 - Piyush Dubey
清理项目并重试。 - Piyush Dubey
你应该将你的故事板图片发布在一个不需要人们获得许可才能查看的网站上。 - rdelmar
4个回答

16

我曾经也遇到过同样的问题,实际上我的问题在于我调用了

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

而不是

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

所以请确保您调用了正确的performSegueWithIdentifier方法 :)


不错,这也是我的情况。 - Zmicier Zaleznicenka
谢谢,我反了个案例。 - Mohammad Zaid Pathan

11

这里输入图片描述

use segue identifier in Push Method and give the proper connection

如果您正在使用标识符,则在需要的地方调用此行。

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

Swift 2.X

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

Swift 3

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

关于您添加的新屏幕。在该屏幕上,当您完成并想要删除它时,只需:

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

如何使用此方法将值传递到下一个视图控制器? - Aniruddha
@Aniruddha -- 昨天我已经回答了你的问题,如果你不介意的话,我解决了你的问题,你能把你的项目发送到我的邮箱karthik.saral@gmail.com吗? - Anbu.Karthik
我正在使用Storyboard。我有两个类A和B。从A中,我想将值传递到B。这是我的做法,但它没有起作用。B *bb = [[B alloc]init]; b.strName = @"Abcd"; [self performSegueWithIdentifier:@"segueName" sender:nil];。请不要介意我无法向您发送项目。 - Aniruddha
@Aniruddha - 没问题,使用这个链接 https://dev59.com/IXjZa4cB1Zd3GeqPg609 ,否则告诉我你的邮箱地址,我会用不同的方法发送示例代码给你。 - Anbu.Karthik

6

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

  • 这个问题中,提问者使用了init而不是instantiateViewControllerWithIdentifier来实例化Storyboard,因此segue没有正确设置。

  • 这个问题中,可能是xcode和模拟器内部出现了一些奇怪的问题,运行Product->Clean有所帮助。

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


0

检查头文件中是否包含UIKIT。我无意中将新的VC设置为View Controller的子类。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接