【问题标题】:Presenting modal viewcontroller over splitviewcontroller at app startup在应用程序启动时通过 splitviewcontroller 呈现模态视图控制器
【发布时间】:2013-09-20 23:39:03
【问题描述】:

由于 UISplitViewController 需要成为 rootviewcontroller,因此我尝试在应用启动时以模态方式呈现一个 viewcontroller,以充当用户的登录/欢迎屏幕。显然,我的 AppDelegate.m 中的以下代码应该可以使用 IOS 6:

#import "AppDelegate.h"
#import "WelcomeViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.

WelcomeViewController *modalWelcomeView = [[WelcomeViewController alloc] initWithNibName:@"Welcome" bundle:nil];
[modalWelcomeView setModalPresentationStyle:UIModalPresentationFullScreen];
[self.splitViewController presentViewController:modalWelcomeView animated:NO Completion:nil];

return YES;
}

然而,对于return YES; 上面的行,我得到一个“在'AppDelegate' 类型的对象上找不到属性'splitViewController'”。我怕我在做傻事……

有什么建议吗?非常感谢。

【问题讨论】:

    标签: ios ipad ios6 uisplitviewcontroller modalviewcontroller


    【解决方案1】:

    唉,我找到了解决方案,实际上在AppDelegate.m 中需要一种稍微不同的方法

    #import "AppDelegate.h"
    #import "WelcomeViewController.h"
    
    @implementation AppDelegate
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    // Override point for customization after application launch.
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    WelcomeViewController *modalWelcomeView = [storyboard instantiateViewControllerWithIdentifier:@"Welcome"];
    [self.window makeKeyAndVisible];
    [self.window.rootViewController presentViewController:modalWelcomeView animated:NO completion:NULL];
    
    return YES;
    

    【讨论】:

    • 好答案,我真的很讨厌 splitVC 始终是 root 并且在它之前不能添加其他 VC,例如登录。
    猜你喜欢
    • 2023-03-18
    • 2012-12-08
    • 1970-01-01
    • 2011-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-05
    相关资源
    最近更新 更多