Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/122.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
Ios 如何在情节提要上获取活动的UIViewController?_Ios_Ipad_Storyboard - Fatal编程技术网

Ios 如何在情节提要上获取活动的UIViewController?

Ios 如何在情节提要上获取活动的UIViewController?,ios,ipad,storyboard,Ios,Ipad,Storyboard,有人能告诉我如何获得以前创建的UIView控制器吗?我正在使用storyboard,并且我已经阅读了苹果公司关于实例化方法的文档EviewController WithiIdentifier:但是这个文档说,每次我调用这个方法时,它都会创建一个ViewController的新实例,我想要的是使用现有的实例 我正在寻找故事板上的UIViewController单例。可能吗 提前谢谢 如果只调用InstanceViewController WithiIdentifier:一次,然后将结果保存为强属性

有人能告诉我如何获得以前创建的UIView控制器吗?我正在使用storyboard,并且我已经阅读了苹果公司关于实例化方法的文档EviewController WithiIdentifier:但是这个文档说,每次我调用这个方法时,它都会创建一个ViewController的新实例,我想要的是使用现有的实例

我正在寻找故事板上的UIViewController单例。可能吗


提前谢谢

如果只调用
InstanceViewController WithiIdentifier:
一次,然后将结果保存为强属性以供重用,那么您将只创建一次。

我有这样一个解决方案:

  • 控制器:
  • 控制员B:
  • 你可以测试,它只是一个实例

    '    SingleController * B = [SingleController shareSingleController];
    [self.navigationController pushViewController:con animated:YES];'
    
    //push ControllerB 
    
    +(instancetype)shareSingleController
    {
        static SingleController * single;
    
        static dispatch_once_t onceToken;
    
        dispatch_once(&onceToken, ^{    
            //a static instance from StoryBoard
    
            single = (SingleController *)[[UIStoryboard storyboardWithName:@"SingleController" bundle:nil]instantiateInitialViewController];
        });
        return single;'
    }