Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xcode/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 向PresentViewController添加延迟_Objective C_Xcode_Uiviewcontroller_Segue_Viewcontroller - Fatal编程技术网

Objective c 向PresentViewController添加延迟

Objective c 向PresentViewController添加延迟,objective-c,xcode,uiviewcontroller,segue,viewcontroller,Objective C,Xcode,Uiviewcontroller,Segue,Viewcontroller,我想知道如何在我的代码中添加1.0秒的延迟: UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UIViewController *homeViewController = (UIViewController *)[storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"]; [self prese

我想知道如何在我的代码中添加1.0秒的延迟:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *homeViewController = (UIViewController *)[storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
[self presentViewController:homeViewController animated:YES completion:nil];
我知道你可以做到:

[self performSelector:@selector(showModalTwo:)withObject:someNumber afterDelay:1.0f];

我只是没有这个或者想做一个函数来segue。任何帮助都会很好。谢谢

不建议在等待操作完成(即登录)时增加延迟,相反,您可以使用Grand Central Dispatch

dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
        //Background Thread
        // do you login logic here

        dispatch_async(dispatch_get_main_queue(), ^(void){
            //Main Thread : UI Updates
            UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
            UIViewController *homeViewController = (UIViewController *)[storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];
            [self presentViewController:homeViewController animated:YES completion:nil];

        });
    });

您想在延迟后执行segue吗??或者什么?是的,我只是想在一段时间后再开始。我有一个登录,所以我想,一旦我给它一个延迟,这将给登录足够的时间来获取我需要的信息,用这个segue传送这工作得很好-感谢帮助人。我很感激!这并不是一个实施延迟的好方法。如果您只是想延迟演示,请使用
dispatch\u after
。实际上,他不需要延迟,他需要在成功登录后在后台执行登录,并演示视图控制器。如果他在延迟后使用dispatch_,他将无法确定登录是否完成