以编程方式创建和呈现模态视图控制器

时间:2013-04-07 20:29:06

标签: ios uiviewcontroller modalviewcontroller presentmodalviewcontroller

我正在尝试以编程方式从使用storyboard启动的视图控制器声明模态视图控制器。我希望看到一个空白视图,但我只能看到第一个控制器的webview。

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSString *fullURL = @"http://google.com";
    NSURL *url = [NSURL URLWithString:fullURL];
    NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
    _viewWeb.delegate=self;
    [_viewWeb loadRequest:requestObj];

    modalViewController=[[UIViewController alloc] init];
    [self presentViewController:modalViewController animated:YES completion:nil];
}

1 个答案:

答案 0 :(得分:11)

你这么快就这么做了。在viewDidLoad中还没有界面。将该代码放入viewDidAppear:代替,看看会发生什么。