- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
dismissViewControllerAnimated:completion: 在我的应用程序中工作正常,除了解雇之间的延迟。
[api loginWithUsername:[dict objectForKey:@"username"] andPassword:[dict objectForKey:@"password"] andSuccessBlock:^(id json) {
NSLog(@"DONE... %@", [json objectForKey:@"status"]);
NSString *status = [json objectForKey:@"status"];
if([status isEqualToString:@"ok"]){
app.user = [json objectForKey:@"data"];
[self dismissViewControllerAnimated:YES completion:nil];
}else{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"could not log you in" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alert show];
}
}];
在我的控制台中,我可以看到回显“DONE...ok”,这意味着回调 block 已执行,但是大约 3-4 秒后模态视图最终被取消。
是什么导致了这种延迟?
最佳答案
如果您不能保证您的 UI 代码在主线程上运行,它可能会在其他线程上运行,在这种情况下,您将遇到几秒钟的延迟!
您可以添加此代码以确保解雇在主线程上运行:
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:YES completion:nil];
});
一般来说,这不是问题,因为您的大部分代码已经在主线程上运行,因为我们主要添加从 UIKit 方法(如 viewDidLoad 等)运行的代码。这些方法保证在主线程上运行。
当您最终在另一个线程上运行代码时,就会出现问题。可能发生这种情况的一种情况是,例如在网络库的完成 block 调用中,请求在后台完成。
关于iphone - dismissViewControllerAnimated :completion: has a couple second delay,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14341739/
我的项目中有 Simple popOver Controller 。我可以使用带有以下代码的操作按钮将其关闭。 [[self presentingViewController] dismissView
我有以下代码将调用模态视图。我在呈现 View Controller 时工作正常,但当我关闭它时,它崩溃了 _surveySummaryTableViewController = [[UITableV
我有一种方法可以从我的 TableView 发送电子邮件。 所以其中一个单元格是“联系我们”单元格,每当它被点击时,我都会使用 MFMailComposeViewController 进入邮件 Vie
我正在使用 QuickDialog 推送登录表单。除了无法关闭 View Controller 外,一切正常。代码如下: - (void)onLogin:(QButtonElement *)butto
我在使用 dismissViewControllerAnimated 时遇到了一些问题,我无法让它执行特定的转换。 我有一个 View Controller (主页),我正在使用模式打开另一个 VC(
我正在开发一个 iPad 应用程序,该应用程序具有一个登录 Controller ,该登录 Controller 可以连接到一个 View Controller 中。登录 Controller 是这样
dismissViewController 不会一直调用它的完成处理程序。我正在展示第一个 View ,当我关闭它时,它会调用完成处理程序,我将在其中展示 2 个 View 。关闭第二个 View 时
我有一个 UIViewController A,此时我的内存为 104 Mb。在 A 中,我通常像这样打开 UIVIewController B: UIViewController *b = [[UI
我正在使用 SVWebViewController .当我在这里展示 View Controller 时 SVModalWebViewController *webViewController = [
我呈现模态视图,它是一个导航 Controller : UINavigationController *nvc = [[UINavigationController alloc] initWithR
我在 IOS6 上使用 Storyboard。我正在尝试返回到之前的 View Controller ,但它不起作用。 我在这里自定义了我的后退按钮。 UIButton *btnBack = [UIB
我试图用自定义动画调用 dismissViewControllerAnimated,但它似乎不起作用。 当我像这样呈现 View Controller 时: cameraUI = UI
我一直在尝试找出如何增加 dismissViewControllerAnimated(true, completion: nil) 的持续时间,但似乎无法在 Apples documentation
我正在使用 Storyboard实现一个 iOS 应用程序,其中一个按钮调用 dismissViewControllerAnimated 以从 View Controller B 返回到前一个 Vie
用户点击按钮调出带有键盘的 View Controller 。在这种情况下,键盘会随着 View Controller 向上滑动,所以看起来键盘是固定在 View Controller 中的。 完成后
我有一个方法 - (void) swipeRight { [self dismissViewControllerAnimated:YES completion:nil]; } 当用户向右滑动时,我用它
我尝试了一些没有真正起作用的东西(更多我想到的东西)。 当使用 [self dismissViewControllerAnimated:YES completion:nil]; 我需要它来运行我要返回
我已经从 apple 下载了 PageControl 示例代码。这是一个带有 UIPageControl 的项目。我对其进行了更改,以便 UIScrollView 具有不同的 View 。对于我想添加
所以....我有一个 View Controller ,当我按下一个按钮时,会出现另一个 View Controller : - (IBAction)searchButtonPressed:(id)s
这是我的应用程序设计。我有 mainController,它显示 secondViewController。现在,我想关闭 secondViewController,然后在 mainControlle
我是一名优秀的程序员,十分优秀!