ios 什么是错误:“NSInvalidArgumentException 原因:应用程序试图在自身上显示模态视图控制器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24955097/
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
What is error: "NSInvalidArgumentException reason: Application tried to present modal view controller on itself
提问by neKuda
When I try to run the app it crashes me This is the message I get:
当我尝试运行该应用程序时,它使我崩溃 这是我收到的消息:
2014-07-25 14:40:28.116 X[13023:60b] (null)
2014-07-25 14:40:29.113 X[13023:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modal view controller on itself. Presenting controller is <GKHostedAuthenticateViewController: 0x10d625f90>.'
*** First throw call stack:
(
0 CoreFoundation 0x00000001028a1495 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x00000001024e399e objc_exception_throw + 43
2 UIKit 0x0000000101190cdc -[UIViewController presentViewController:withTransition:completion:] + 4100
3 CoreFoundation 0x0000000102896f1c __invoking___ + 140
4 CoreFoundation 0x0000000102896dc4 -[NSInvocation invoke] + 308
5 UIKit 0x0000000101181abc -[_UIDelayedPresentationContext finishDelayedPresentation:] + 201
6 GameCenterUI 0x000000010c97f330 __41-[GKRemoteViewController setupRemoteView]_block_invoke + 37
7 CoreFoundation 0x0000000102896f1c __invoking___ + 140
8 CoreFoundation 0x0000000102896dc4 -[NSInvocation invoke] + 308
9 libdispatch.dylib 0x000000010340a851 _dispatch_call_block_and_release + 12
10 libdispatch.dylib 0x000000010341d72d _dispatch_client_callout + 8
11 libdispatch.dylib 0x000000010340d3fc _dispatch_main_queue_callback_4CF + 354
12 CoreFoundation 0x00000001028ff289 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
13 CoreFoundation 0x000000010284c854 __CFRunLoopRun + 1764
14 CoreFoundation 0x000000010284bd83 CFRunLoopRunSpecific + 467
15 GraphicsServices 0x0000000103efdf04 GSEventRunModal + 161
16 UIKit 0x0000000101090e33 UIApplicationMain + 1010
17 X 0x00000001000064c3 main + 115
18 libdyld.dylib 0x000000010366e5fd start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
What could be the problem? Until now it worked well suddenly it happened Thank you to all helpers
可能是什么问题呢?直到现在它运行良好突然发生了谢谢所有帮助者
update: @Sviatoslav Yakymiv found this i think
更新:@Sviatoslav Yakymiv 发现这个我认为
- (void)authenticateLocalUser {
if (!gameCenterAvailable) return;
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
if (SYSTEM_VERSION_LESS_THAN(@"6.0"))
{
// ios 5.x and below
[localPlayer authenticateWithCompletionHandler:^(NSError *error)
{
[self checkLocalPlayer];
}];
}
else
{
// ios 6.0 and above
[localPlayer setAuthenticateHandler:(^(UIViewController* viewcontroller, NSError *error) {
if (!error && viewcontroller)
{
[viewcontroller presentViewController:viewcontroller animated:YES completion:nil];
}
else
{
[self checkLocalPlayer];
}
})];
}
}
}
What I can change it without a crash? thanks
我可以在不崩溃的情况下改变它吗?谢谢
回答by Sviatoslav Yakymiv
You are attempting to present controller from itself. Probably your code contains something like following:
您正试图从自身呈现控制器。可能您的代码包含以下内容:
[self presentViewController:self completion:nil];
Now after I saw your code I can provide working code:
现在,在我看到您的代码后,我可以提供工作代码:
Replace
代替
[viewcontroller presentViewController:viewcontroller animated:YES completion:nil];
with
和
[[UIApplication sharedApplication].keyWindow.rootViewController presentViewController:viewcontroller animated:YES completion:nil];
回答by zeeawan
Same error for me when I accidentally called
当我不小心打电话时,我也犯了同样的错误
presentViewController:
twice.
两次。
回答by Apurv
You have not created your xib properly. Check all your connections and delegates. Your last changes to xib have introduced some problems. This exception throws when your xib / storyboard are not proper.
您没有正确创建您的 xib。检查您的所有联系人和代表。您对 xib 的最后更改引入了一些问题。当您的 xib / 故事板不正确时,将引发此异常。