我正在开发一个 iPad 应用程序,该应用程序具有一个登录 Controller ,该登录 Controller 可以连接到一个 View Controller 中。登录 Controller 是这样声明的:
@interface LoginController : UIViewController <UITextFieldDelegate>
Storyboard有(正如预期的那样)用户名和密码文本字段以及用于身份验证和登录到主应用程序的按钮。按钮调用 shouldPerformSegueWithIdentifier(...) 函数, View 从登录 View 切换到主视图。
当用户在密码文本框上按回车键时,我还想以编程方式模仿这一点。我已经捕获了这个事件,但我似乎无法让切换发生。我使用的代码是:
if (theTextField == self.password)
{
BOOL loginSuccessful = [self shouldPerformSegueWithIdentifier:@"switchToViewer" sender:self];
if (loginSuccessful == YES)
{
[self dismissViewControllerAnimated:YES completion:^{
NSLog(@"I should be dismissing here!\n");
}];
}
}
但是,该 View 永远不会被忽略。我应该注意到这是在 iOS 7 上,我不知道这是否重要。有什么想法吗?
编辑:我现在的解决方法是欺骗按钮触摸事件:
[self.signIn sendActionsForControlEvents: UIControlEventTouchUpInside];
Hacky,但它有效:)
最佳答案
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
关于ios - dismissViewControllerAnimated 不会关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19104137/