gpt4 book ai didi

ios - Xcode 5 Storyboard - presentViewController 不呈现我现有的 Viewcontroller 并显示黑屏

转载 作者:行者123 更新时间:2023-11-29 02:33:15 27 4
gpt4 key购买 nike

我有两个名为 ViewController 和 SecondViewController 的 View Controller 。从第一个 View Controller 我试图在 5 秒后调用我的 SecondViewController。但它会给我黑屏而不是我预期的 View 。

这是我的 View Controller 代码,

`

#import "ViewController.h"
#import "SecondViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
[self performSelector:@selector(loadingNextView) withObject:nil afterDelay:5.0f];

}

-(void)loadingNextView{
SecondViewController *SVC = [[SecondViewController alloc] initWithNibName:nil bundle:nil];
SVC.view.backgroundColor = [UIColor redColor];
[self presentViewController:SVC animated:YES completion:NULL];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end`

请推荐。如果我使用按钮进行导航那么它的工作,但我的需要是在计时器上自动调用。

最佳答案

如果您的 SecondViewController 位于 Storyboard 而不是 alloc init 中,则您必须使用 instantiateViewControllerWithIdentifier

[self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];

不要忘记在 Storyboard中提供 Controller 的标识符。所以方法将是

-(void)loadingNextView{
[self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
SVC.view.backgroundColor = [UIColor redColor];
[self presentViewController:SVC animated:YES completion:NULL];
}

关于ios - Xcode 5 Storyboard - presentViewController 不呈现我现有的 Viewcontroller 并显示黑屏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26649564/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com