Create and Present modal view controller programmatically

删除回忆录丶 提交于 2019-11-30 18:11:02

问题


I am trying to programmatically declare a modal view controller from a view controller launched using storyboard. I would expect to see a blank view coming up but instead I only see the webview from the first controller.

- (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:


You're doing this too soon. There's no interface yet, in viewDidLoad. Put that code into viewDidAppear: instead, and see what happens.



来源:https://stackoverflow.com/questions/15867447/create-and-present-modal-view-controller-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!