iphone - Xcode Objective-C 转场 "Presentation in Progress"

标签 iphone ios xcode segue afnetworking

我正在尝试开发一个允许用户使用 AFNetworking 登录的应用程序。我的数据库设置正确,一切似乎都工作正常,除非用户首次登录。

我所拥有的非常简单:

[[API sharedInstance] commandWithParams:params
                               onCompletion:^(NSDictionary *json) {
                                   //result returned

                                   NSDictionary* res = [[json objectForKey:@"result"] objectAtIndex:0];

                                   if ([json objectForKey:@"error"]==nil && [[res objectForKey:@"UserID"] intValue]>0) {
                                       [[API sharedInstance] setUser: res];
                                       [self performSegueWithIdentifier:@"Login" sender:self];
                                   } else {
                                       //error
                                       [UIAlertView title:@"Error" withMessage:[json objectForKey:@"error"]];
                                   }

                               }];

基本上,上面的代码返回用户登录详细信息的结果,仅当登录详细信息匹配时才成功。正如您在上面看到的,我明确地在整个应用程序中使用的 sharedInstance 中设置了用户。设置用户后,我尝试执行 segue,因为这是登录按钮应该做的。

segue 确实发生并且程序可以运行,但是有 2 个问题我无法解决,我已经花了几个小时试图修复它。首先,我在 Xcode 的输出窗口中收到消息:

Warning: Attempt to present UITabBarController on LoginVC while a presentation is in progress!

其次,为了测试用户设置是否正确,在配置文件屏幕(第一个屏幕转到)上有一个标签,其文本设置为:

NSString stringWithFormat:@"Welcome %@",[[[API sharedInstance] user] objectForKey:@"username"]];

用户名是否实际出现或显示为 (null) 是一个成功或失败的问题:

enter image description here

您还可以看到我在那里制作的按钮,用于将用户的值打印到输出窗口。即使当消息是“欢迎(null)”并且我按下按钮时,所有值都正确存在,所以我不确定为什么字符串有时会显示为 null。

这是关于我遇到的问题的 Storyboard设置:

enter image description here

如果有人能在这方面帮助我,我将不胜感激。

最佳答案

正如您正确诊断的那样,问题肯定是对 segue 的一些奇怪和/或重复调用。查看您的项目,问题是您的“登录”按钮既有 IBAction 方法,也有从该登录屏幕到下一个 Controller (选项卡栏 Controller )的 segue:

both IBAction and segue

这是个问题,因为 segue 会在您按下按钮时触发,但会被您的 - (IBAction)login:(id)sender 代码再次触发。

因为您有一个 IBAction,所以 segue 应该不是从按钮到下一个 Controller ,而是从 Controller 本身。因此,删除从按钮到下一个屏幕的现有 Login segue,并从 Controller 本身重新创建它:

create segue from controller to next scene

为新的 segue 提供“Login”标识符,现在您的“Login”按钮不会自动执行 segue 本身,而是让 IBAction 完成它的工作并手动 performSegueWithIdentifier 视情况而定。

关于iphone - Xcode Objective-C 转场 "Presentation in Progress",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13256876/

相关文章:

ios - 如何正确桥接 Swift 错误与 NSError 的参数

objective-c - 我们应该什么时候使用 NSString 和 NSMutableString?

xcode - 错误 : Command/Applications/Xcode. app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang 失败,退出代码为 1

ios - 如何使用页面控件在 iOS 中开发部分

iphone - CATiledLayer 的背景图片

iphone - 委托(delegate)和通知有什么区别?

iphone - iOS 6 - Facebook 共享程序失败并出现错误 "The proxied app is not already installed"

iOS Fitbit 注销

xcode - 如何将整个 Xcode IDE 主题设置为亮暗色?

ios - 从小部件扩展访问核心数据