0

我已经尝试了这个论坛的所有解决方案,但仍然无法解决。有人可以帮我解决这些问题吗?当 NSUserDefault 从 Urban Airship 读取密钥 @"url" 时,我希望应用程序打开包含 tableView 的 inboxData 类。

这是来自 SampleViewController 类;

-(void)viewDidAppear:(BOOL)animated{

    [super viewDidAppear:animated];

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *action_9 = [defaults objectForKey:@"url"];

    if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"url"] isEqualToString:@"aa9"])

{

        inboxData *screen=[[inboxData alloc]initWithNibName:@"inboxData" bundle:nil];
        screen.strGetTableSelect=@"1";
        UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:screen];
        [self presentModalViewController:navigationController animated:YES];

    }
}

它返回这些错误..

警告:尝试在视图不在窗口层次结构中的 SampleViewController 上呈现 UINavigationController

4

1 回答 1

1

您的 SampleViewController 不在窗口层次结构中,您需要在窗口中设置。

在你的 appDelegate 中,这样做,

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.viewController = [[SampleViewController alloc] initWithNibName:@"SampleViewController" bundle:nil];
    self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];
    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];
    return YES;
}

如果您使用的是故事板,请在 didFinishLaunchingWithOptions 方法中像这样使用,

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone"
                                                             bundle: nil];
 
    SampleViewController *mainViewController = (SampleViewController*)[mainStoryboard
                                                       instantiateViewControllerWithIdentifier: @"SampleViewController"];
 
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:mainViewController];
 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.window setRootViewController:navigationController];
    [self.window setBackgroundColor:[UIColor whiteColor]];
    [self.window makeKeyAndVisible];
 
    return YES;
}

在您的视图控制器中,

-(void)viewDidAppear:(BOOL)animated{

    [super viewDidAppear:animated];

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *action_9 = [defaults objectForKey:@"url"];

    if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"url"] isEqualToString:@"aa9"])

{
        inboxData *screen=[[inboxData alloc]initWithNibName:@"inboxData" bundle:nil];
        screen.strGetTableSelect=@"1";
        [self presentModalViewController:screen animated:YES];

    }
}
于 2013-10-11T09:19:31.987 回答