objective-c NSInvalidArgumentException

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

NSInvalidArgumentException

iphoneobjective-ccocoa-touch

提问by Alan

I'm getting a crash from this routine after adding the :(id)sender so I could determine which button called it. When set up as plain old toggleView3 it works perfectly. The crash occurs when detailView is toggled back to docView.

添加 :(id)sender 后,我从这个例程中崩溃了,所以我可以确定哪个按钮调用了它。当设置为普通的旧 toggleView3 时,它可以完美运行。当 detailView 切换回 docView 时会发生崩溃。

'NSInvalidArgumentException', reason: '*** -[RootViewController toggleView3]: unrecognized selector sent to instance 0x524a00' 2009-04-07 12:29:44.421 eTarot[11405:20b] Stack:

'NSInvalidArgumentException', reason: '*** -[RootViewController toggleView3]: unrecognized selector sent to instance 0x524a00' 2009-04-07 12:29:44.421 eTarot[11405:20b] Stack:

-(IBAction)toggleView3:(id)sender{


    if (detailViewController == nil) {
        [self loadDetailViewController];
    }

    UIView *docView = docViewController.view;
    UIView *detailView = detailViewController.view;

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1];
    [UIView setAnimationTransition:([docView superview] ? UIViewAnimationTransitionFlipFromRight : UIViewAnimationTransitionFlipFromLeft) forView:self.view cache:YES];

    if ([docView superview] != nil) {
        [detailViewController viewWillAppear:YES];
        [docViewController viewWillDisappear:YES];
        [docView removeFromSuperview];

        [self.view addSubview:detailView];
        [self.view insertSubview:detailNavigationBar aboveSubview:detailView];
        [docViewController viewDidDisappear:YES];
        [detailViewController viewDidAppear:YES];

    } else {
        [docViewController viewWillAppear:YES];
        [detailViewController viewWillDisappear:YES];
        [detailView removeFromSuperview];
        [detailNavigationBar removeFromSuperview];
        [self.view addSubview:docView];
        [detailViewController viewDidDisappear:YES];
        [docViewController viewDidAppear:YES];
    }
    [UIView commitAnimations];
}

回答by Chuck

You're sending a view the message toggleView3when the correct name of the selector is toggleView3:— that is, with a colon and argument. They may look similar to you, but they're totally different methods to Objective-C.

You're sending a view the message toggleView3when the correct name of the selector is toggleView3:— that is, with a colon and argument. 它们可能看起来与您相似,但它们是与 Objective-C 完全不同的方法。

回答by Marc Charbonneau

That exception means your application is calling toggleView3 without the :sender argument somewhere. Since your new method requires an argument, it's the same as calling a method that never existed.

该异常意味着您的应用程序在某处调用 toggleView3 而没有 :sender 参数。由于您的新方法需要一个参数,因此它与调用一个从未存在过的方法相同。

If you look through the stack trace in the debugger it should be pretty clear where it's coming from. There's probably a warning in the build results, too.

如果您查看调试器中的堆栈跟踪,应该很清楚它来自哪里。构建结果中也可能有警告。