xcode NSInvalidArgumentException 原因 Receiver has no segue with identifier

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9568034/
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-09-14 23:32:08  来源:igfitidea点击:

NSInvalidArgumentException reason Receiver has no segue with identifier

objective-cxcodesegueuistoryboardsegue

提问by Simon Barkhuizen

I have problem I've been sitting with. I have a UIViewController Listand a UIViewController Login. On LoginI have a button "Done", also another hidden button on the same UIViewController that has a segue to List(Type: push). I gave it an identifier in the interface builder of xcode named "LoginToList". Now from another class (a class that runs while Loginis the active controller) I call:

我有问题,我一直坐着。我有一个 UIViewControllerList和一个 UIViewController Login。在Login我有一个按钮“完成”,还有同一个 UIViewController 上的另一个隐藏按钮,它有一个转场List(类型:推送)。我在 xcode 的界面构建器中给了它一个名为“LoginToList”的标识符。现在从另一个类(一个运行时Login是活动控制器的类)我调用:

[[Login sharedLogin] performSegueWithIdentifier:@"LoginToList"];

The Loginclass clearly has a segue with identifier "LoginToList"

所述Login类显然有与标识符的SEGUE"LoginToList"

Yet I keep getting:

但我不断得到:

 'NSInvalidArgumentException', reason: 'Receiver (<Login: 0x6d79d90>) has no segue with identifier 'LoginToList''

the + (id) sharedLoginlooks like this:

+ (id) sharedLogin看起来像这样:

+ (id) sharedLogin {
    static Login *sharedLogin = nil;

    @synchronized(self) {
        if (sharedLogin == nil) {
            sharedLogin = [[self alloc] init];
        }

        return sharedLogin;
    }
}

If anyone has any idea why it says that, I'd be glad to hear it! :DI don't know if I'm missing something stupid but I can't spot it :(

如果有人知道为什么这么说,我很高兴听到它!:D我不知道我是否遗漏了一些愚蠢的东西,但我无法发现它:(

EDIT: I have create a segue in the interfacebuilder (ctrl + click drag from Loginto List) using the UIViewControllers themselfves (Login& List). Then I named the segue "LoginToList"in other words I gave it that identifier. I clicked the segue and at the top-right there was a "Identifier" field which I used.

编辑:我使用 UIViewControllers 自己(& )在 interfacebuilder 中创建了一个 segue(ctrl + 单击从Loginto拖动)。然后我给 segue 命名,换句话说我给了它那个标识符。我点击了转场,在右上角有一个我使用的“标识符”字段。ListLoginList"LoginToList"

I Still get the error saying Loginhas no segue with identifier "LoginToList". sad

我仍然收到错误说Loginhas no segue with identifier "LoginToList"。伤心

回答by user1678907

As far as your code snippet goes, it looks like you tried to create a singleton out of the Login Controller, but only did it half way.

就您的代码片段而言,您似乎试图从登录控制器中创建一个单例,但只成功了一半。

The seque can't be found because the the Controller was initialized using the storyboard, not using your shared class method. So you end up having two independent instances. Additionally, your class method does not initialize the controller with the storyboard bindings, so you don't have any seques here.

找不到序列,因为控制器是使用情节提要初始化的,而不是使用您的共享类方法。所以你最终有两个独立的实例。此外,您的类方法不会使用情节提要绑定初始化控制器,因此您在这里没有任何序列。

You should try to hand a reference of the LoginController's instance (initialized unsing storyboard segues etc.) to the 'other class' and use that one.

您应该尝试将 LoginController 的实例(初始化的故事板 segues 等)的引用传递给“其他类”并使用该实例。

回答by user1678907

sharedLogin = [[self alloc] init];

try this

尝试这个

sharedLogin = [self.storyboard instantiateViewControllerWithIdentifier:@"xxxx"];

sharedLogin = [self.storyboard instantiateViewControllerWithIdentifier:@"xxxx"];

you must set IdentifierName in storyboard LoginViewController

您必须在情节提要 LoginViewController 中设置 IdentifierName

回答by john.k.doe

without knowing about what your init does ...

不知道你的 init 做了什么......

i found in attempting to dynamically [[alloc] init]a view controller for use like this, i had to call initWithNibName:bundle:, and thus i had to put my view controller in a separate xib class so it didn't get confused in the storyboard and leave warnings about an unreachable scene.

我发现在尝试动态[[alloc] init]像这样使用的视图控制器时,我不得不调用initWithNibName:bundle:,因此我不得不将我的视图控制器放在一个单独的 xib 类中,这样它就不会被混淆在故事板中,并留下有关无法访问场景的警告。

without initWithNibName:bundle:, my guess is that your call to [[alloc] init] in sharedLoginis not properly tying the UIStorybardSegue*that you you have clearly created to the Login view controller in a way that it can be used from the object returned .

如果没有initWithNibName:bundle:,我的猜测是您在sharedLogin 中对 [[alloc] init] 的调用没有正确地将您清楚地创建的UIStorybardSegue*以可以从对象中使用的方式绑定到登录视图控制器回来 。

(my situation is that i had a popover in iPad and a regular navigation segue in iPhone. for iPhone, i am using the hidden button with segue in iPhone, but it is performing a segue to a scene and view-controller that undoubtedly gets initialized in awakeFromNib: . for iPad, i'm putting into a popover, and the popover isn't connected to anything …?and gets initialized with initWithNibName:bundle: to the item that is in a separate .xib file.]

(我的情况是,我在 iPad 中有一个弹出框,在 iPhone 中有一个常规的导航 segue。对于 iPhone,我在 iPhone 中使用带有 segue 的隐藏按钮,但它正在对场景和视图控制器执行 segue,这无疑会被初始化在awakeFromNib: . 对于iPad,我正在放入一个popover,并且popover 没有连接到任何东西...?并使用initWithNibName:bundle: 初始化到单独的.xib 文件中的项目。]

回答by DoS

first, i believe segues should follow camel case rules. change to...

首先,我认为 segue 应该遵循驼峰规则。改成...

loginToList

second, disconnect and reconnect your views in ib.

其次,断开并重新连接您在 ib 中的视图。

third, clean your project (shift-command-k).

第三,清理你的项目(shift-command-k)。

lastly, you should be using something like this method...

最后,你应该使用类似这种方法的东西......

 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"loginToList"]) {
        [[segue destinationViewController] setDelegate:self];
    }

}

for your segue. then setup a delegate protocol method to dismiss the view controller.

为您的转场。然后设置一个委托协议方法来关闭视图控制器。