Objective c 在故事板ios7中添加视频作为启动

Objective c 在故事板ios7中添加视频作为启动,objective-c,ios7,uinavigationcontroller,storyboard,Objective C,Ios7,Uinavigationcontroller,Storyboard,我想在应用程序开始时显示一个视频,就像一个水花。我的整个应用程序将在导航。首先,我将视频添加到splashViewController中,并在appDelegate中将其设置为rootView,然后只需再次将mainViewController设置为rootView - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { U

我想在应用程序开始时显示一个视频,就像一个水花。我的整个应用程序将在导航。首先,我将视频添加到splashViewController中,并在appDelegate中将其设置为rootView,然后只需再次将mainViewController设置为rootView

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
    splashViewController = [[SplashViewController alloc] init];
    splashViewController = (SplashViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"SplashViewController"];
    self.window.rootViewController = splashViewController;

    [NSTimer scheduledTimerWithTimeInterval:9.0 target:self selector:@selector(removeSplashScreen:) userInfo:nil repeats:NO];

    return YES;
}

-(void)removeSplashScreen:(id)userInfo
{
    [splashViewController removeFromParentViewController];

    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
    mainViewController = [[MainViewController alloc] init];
    mainViewController = (MainViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"MainViewController"];
    self.window.rootViewController = mainViewController;
}
现在我想从这个mainViewController开始导航。我在mainViewController中使用情节提要并从
Editor>Embed in>navigation Controller
添加导航。不要以编程方式进行。但是我知道使用Nib.xib实现它的方法。在这里,我还把
箭头
(表示起始VC的箭头)标记放在它的旁边。但当我从mainVC点击一个按钮转到下一个VC时,它就崩溃了。如何在此处设置导航

如果有人有答案,请与我分享。先谢谢你

我的故事板的场景:

好吧,尽管我在评论中给出了建议,但以下是实现这一目标的方法:

显示飞溅:

//StoryBoard
UIStoryboard *mainStoryboard = [UIStoryboard 
                                   storyboardWithName:@"Main" bundle: nil];
//Splash Controller                                
SplashViewController *splashViewController = [mainStoryboard 
                instantiateViewControllerWithIdentifier:@"SplashViewController"];
//Show it                                 
[self.window.rootViewController presentViewController:splashViewController 
                                             animated:NO completion:nil];
[self dismissViewControllerAnimated:YES completion:nil];
-(void)removeSplashScreen:(id)userInfo
{
   [self dismissViewControllerAnimated:YES completion:nil];
}
删除它:

//StoryBoard
UIStoryboard *mainStoryboard = [UIStoryboard 
                                   storyboardWithName:@"Main" bundle: nil];
//Splash Controller                                
SplashViewController *splashViewController = [mainStoryboard 
                instantiateViewControllerWithIdentifier:@"SplashViewController"];
//Show it                                 
[self.window.rootViewController presentViewController:splashViewController 
                                             animated:NO completion:nil];
[self dismissViewControllerAnimated:YES completion:nil];
-(void)removeSplashScreen:(id)userInfo
{
   [self dismissViewControllerAnimated:YES completion:nil];
}

编辑:还是不工作

也许你叫它快。这样做:

viewDidLoad

   [NSTimer scheduledTimerWithTimeInterval:9.0 
                                    target:self 
                                  selector:@selector(removeSplashScreen:) 
                                  userInfo:nil repeats:NO];
要删除的功能:

//StoryBoard
UIStoryboard *mainStoryboard = [UIStoryboard 
                                   storyboardWithName:@"Main" bundle: nil];
//Splash Controller                                
SplashViewController *splashViewController = [mainStoryboard 
                instantiateViewControllerWithIdentifier:@"SplashViewController"];
//Show it                                 
[self.window.rootViewController presentViewController:splashViewController 
                                             animated:NO completion:nil];
[self dismissViewControllerAnimated:YES completion:nil];
-(void)removeSplashScreen:(id)userInfo
{
   [self dismissViewControllerAnimated:YES completion:nil];
}

很高兴分两步帮助您

第一步- 您的didFinishLaunchingWithOptions代码几乎是正确的,但它是否工作并不重要。因此,让我们关注第二步

步骤2-在-(无效)删除PlashScreen:(id)用户信息

“此行足以从情节提要加载主视图控制器” -下一行是正确的
self.window.rootViewController=mainViewController; 代码现在似乎正在运行,但仍然缺少导航控制器,因为您已从情节提要而不是导航控制器加载mainviewcontroller

- two solution for it
1- load navigation controller in place of mainviewcontroller(give a storyboard id to navigation controller , load it , and make it as root controller) --i will always go with it
2- make a navigation controller with allocating it & make its rootviewcontroller the mainviewcontroller

-----------------工作代码-----------------

因此,根据pawan给出的答案,解决方案是:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
    splashViewController = (SplashViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"SplashViewController"];
    self.window.rootViewController = splashViewController;

    [NSTimer scheduledTimerWithTimeInterval:9.0 target:self selector:@selector(removeSplashScreen:) userInfo:nil repeats:NO];

    return YES;
}

-(void)removeSplashScreen:(id)userInfo
{
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main" bundle: nil];
    mainViewController = [[MainViewController alloc] init];
    mainViewController = (MainViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"MainViewController"];

    navigationContoller = [[UINavigationController alloc] initWithRootViewController:mainViewController];
    self.window.rootViewController = navigationContoller;
}

:)

如果您阅读《苹果人机界面指南》,您会发现不推荐使用闪屏。没有像闪屏这样的概念,而是启动图像。请记住,不遵守指南可能导致应用程序被拒绝感谢您的评论并提醒指南。但我想这样做。在过去的nib文件中,我使用视频飞溅应用程序&应用程序商店从不拒绝它。我同意
meda
不遵守指导原则会导致你的应用程序被拒绝。尽管您所追求的并不违反指导原则,因为这只是一个播放视频的
UIViewController
。因此,据我所知,您的应用程序将启动,用户将看到启动图像,然后出现的第一个视图控制器将是
SplashViewController
。这似乎与此无关,但我会注意到,这与
xcode IDE
无关,因此请不要使用该标记。虽然我同意您的建议,但他们试图实现的目标并不违背这一点。指导方针提到了发布图像之后发生的事情,由您决定(如是),因此添加一个播放视频的视图控制器(仅此而已)是完全可以接受的,它没有说这是不允许的。是的。这是我的观点。这并不是说我没有在这里添加任何飞溅。是的。但在那之后,我只想添加一个splashVC。就是这样。是的,你们是对的,我到底该评判谁。它显示了指向“dismissViewControllerAnimated:YES”的错误并说“No visible@interface for'AppDelegate'声明了选择器“dismissViewControllerAnimated:completion:”meda@Tulon是的,就像大力水手说的,在
AppDelegate
中显示它,将其隐藏在SplashViewController中非常感谢pawan。它正在工作:)。我选择您的第二个解决方案。>>“2-创建一个导航控制器并分配它&将其rootviewcontroller设置为mainviewcontroller”,但这里将进行一些编辑。这是“2-使用分配的方式创建导航控制器并将其rootviewcontroller设置为navigationController”。非常感谢您的解释和选择。:)