viewDidLoad 中的 UINavigationController pushViewController 不起作用 [英] UINavigationController pushViewController in viewDidLoad not working

查看:27
本文介绍了viewDidLoad 中的 UINavigationController pushViewController 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 AppDelegate 中有以下代码:

I have the following code in my AppDelegate:

#import <UIKit/UIKit.h>

@class PersonalDiarySystemViewController;

@interface PersonalDiarySystemAppDelegate : NSObject <UIApplicationDelegate> {
    UIWindow *window;
    PersonalDiarySystemViewController *viewController;
    UINavigationController *navigationController;

}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet PersonalDiarySystemViewController *viewController;
@property (nonatomic, retain) UINavigationController *navigationController;

@end

#import "PersonalDiarySystemAppDelegate.h"
#import "PersonalDiarySystemViewController.h"

@implementation PersonalDiarySystemAppDelegate

@synthesize window;
@synthesize viewController;
@synthesize navigationController;

#pragma mark -
#pragma mark Application lifecycle

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    

    // Override point for customization after application launch.

    // Set the view controller as the window's root view controller and display.
    self.window.rootViewController = self.viewController;
    navigationController = [[UINavigationController alloc] initWithRootViewController:self.window.rootViewController];  
    navigationController.navigationBar.tintColor = [UIColor   
                                                         colorWithRed:217.0/255   
                                                         green:33.0/255 
                                                         blue:0   
                                                         alpha:1];
    navigationController.navigationBarHidden = YES;
    [self.window addSubview:navigationController.view];
    [self.window makeKeyAndVisible];

    return YES;
}

我的 rootviewcontroller 尝试在其 viewDidLoad 方法中将另一个视图控制器加载到导航控制器堆栈中,但由于某种原因视图没有被推送:

My rootviewcontroller tries to load another viewcontroller into the navigation controllers stack in its viewDidLoad method but for some reason the view is not getting pushed:

-(void) viewDidLoad{    
    lvc = [[LoginViewController alloc] init];
    //lvc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [lvc setDelegate:self]; 
    //[self presentModalViewController:lvc animated:YES];   
    [self.navigationController pushViewController:lvc animated:YES];    
}

我没有收到任何错误,所以不确定发生了什么......使用 presentModalViewController 工作......所以真的很困惑!!

I'm getting no errors so not sure whats going on...using presentModalViewController works...so really am confused!!

推荐答案

您需要将 lvc 分配给 LoginViewController.

You need to assign lvc to LoginViewController.

- (void) viewDidAppear
{    
    [self performSelector:@selector(loginCheck:) withObject:nil afterDelay:0.5];
}    
- (void) loginCheck:(id)sender
{
    LoginViewController * lvc = [[LoginViewController alloc] init];
    //lvc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
    [lvc setDelegate:self]; 
    //[self presentModalViewController:lvc animated:YES];   
    [self.navigationController pushViewController:lvc animated:YES];   
}

这篇关于viewDidLoad 中的 UINavigationController pushViewController 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆