从appdelegate呈现视图控制器

时间:2015-02-11 21:23:37

标签: ios objective-c appdelegate

我没有使用LaunchScreen.xib。我正在使用故事板进行启动画面。我正在调用API来获取启动图像。我在app delegate中这样做。我可以在视图控制器上显示图像,但是一旦显示图像,我就无法转到另一个控制器。

以下是AppDelegate中的内容:

-(void)connectionDidFinishLoading:(NSURLConnection *)connection{


self.window.frame=CGRectMake(0, 200, 100,30);

[self.window addSubview:[self convertImage: image]];

//upto here everything is fine

//now i am trying to wait for 3 seconds and call another view controller

sleep(3);

ViewController *login=[[ViewController alloc]initWithNibName:@"Login" bundle:nil];
[self presentviewcontroller:....]; // not able to present another controller

}

2 个答案:

答案 0 :(得分:3)

您可以使用:

[[self window].rootViewController presentViewController:login animated:YES completion:nil];

答案 1 :(得分:1)

Swift 3

self.window?.rootViewController?.present(viewController, animated: true, completion: nil)