Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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 如何在viewDidLoad中加载视图控制器?_Ios_Objective C_Nsdate - Fatal编程技术网

Ios 如何在viewDidLoad中加载视图控制器?

Ios 如何在viewDidLoad中加载视图控制器?,ios,objective-c,nsdate,Ios,Objective C,Nsdate,我在viewDidLoad中有以下代码。我想比较在nsuserdefaults restrictionTime中保存的nsdate if ([[NSDate date]timeIntervalSinceDate:[restrictionTime objectForKey:@"time"]] < 86400) { ResultsViewController *destinationViewController = [[ResultsViewController alloc]init

我在viewDidLoad中有以下代码。我想比较在nsuserdefaults restrictionTime中保存的nsdate

if ([[NSDate date]timeIntervalSinceDate:[restrictionTime objectForKey:@"time"]] < 86400) {

    ResultsViewController *destinationViewController = [[ResultsViewController alloc]init];
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    destinationViewController = [storyboard instantiateViewControllerWithIdentifier:@"results"];

    [self presentViewController:destinationViewController animated:NO completion:^{
    }]; // !!!!! this line 

}

上面的NSLog返回2167.23445

如果您的应用程序递归运行viewDidLoad,则我认为您正在通过以下方式再次调用同一个VC:

    destinationViewController = [storyboard instantiateViewControllerWithIdentifier:@"results"];

你能证实这不是故意的吗?我不明白为什么你可能会再次实例化同一个VC。如果这是问题所在,我建议您在该场景为真时仔细检查实际要实例化的VC的名称。

您正在该块中创建两个视图控制器:

// Creating a ResultsViewController
ResultsViewController *destinationViewController = [[ResultsViewController alloc]init];

// Creating (I assume) another ResultsViewController
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
destinationViewController = [storyboard instantiateViewControllerWithIdentifier:@"results"];

你确定你的意思是“递归”吗?还是说两次?另外,正如其他人所提到的,您可能应该在-viewdidappease中显示新的控制器:

在视图出现之前,不要显示任何视图控制器!在视图生命周期中调用了
–viewdide:
方法之前,您不应该尝试将新视图推入导航堆栈。100%确定我没有调用同一个VCD。您可以中断正在调用的viewdideload函数的开头,并查看堆栈跟踪,以查看是谁在调用它吗?
// Creating a ResultsViewController
ResultsViewController *destinationViewController = [[ResultsViewController alloc]init];

// Creating (I assume) another ResultsViewController
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
destinationViewController = [storyboard instantiateViewControllerWithIdentifier:@"results"];