更改根视图控制器后,UINavigation无法在我的iphone应用程序中运行

时间:2013-06-08 05:56:50

标签: iphone ios uinavigationcontroller navigationcontroller uinavigation

我正在为iphone开发ios应用程序。 我的登录界面遇到问题.. 我已开发app withoughtlogin screen.but现在我想首先提供登录选项,登录后我想显示我的实际应用程序屏幕。

所以我用代码做的事情如下......

首先使用登录界面我在appdeleget.m中调用的函数如下所示。

-(bool)DeafultSideBar{

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    ViewController *homeViewController = [[ViewController alloc]init];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:homeViewController];
      [navController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationbar.png"] forBarMetrics:UIBarMetricsDefault];

    SlideTabViewController *rootController = [[SlideTabViewController alloc] initWithRootViewController:navController];
    _viewController = rootController;

    LeftSlideViewController    *leftController = [[LeftSlideViewController alloc] init];
    rootController.leftViewController = leftController;
    // [FBLoginView class];

    self.window.rootViewController = rootController;

    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];

       return YES;


}

这是我从 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions method of AppDelegete. m file

调用的函数

现在我想显示登录界面,所以我已经登录了Viewcontroller,然后我修改了我的 -

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

用这个方法..

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


    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    LogInViewController *logInViewController = [[LogInViewController alloc]init];


    self.window.rootViewController = logInViewController;

    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];

    return YES;




}

并且我在登录界面中有一个按钮,点击该按钮我做的事情与之前在我的应用程序中没有登录屏幕时所做的相同,如下所示。

- (IBAction)SignInCalled:(id)sender {
    AppDelegate *appdelegete=[[AppDelegate alloc]init];

    appdelegete.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.

    ViewController *homeViewController = [[ViewController alloc]init];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:homeViewController];
    [navController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationbar.png"] forBarMetrics:UIBarMetricsDefault];

    SlideTabViewController *rootController = [[SlideTabViewController alloc] initWithRootViewController:navController];
    _viewController = rootController;

    LeftSlideViewController    *leftController = [[LeftSlideViewController alloc] init];
    rootController.leftViewController = leftController;



    [UIView beginAnimations:@"flipping view" context:nil];
    [UIView setAnimationDuration:0.8];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES];
    //[self presentModalViewController:rootController animated:YES];
    appdelegete.window.rootViewController = rootController;

    appdelegete.window.backgroundColor = [UIColor whiteColor];
    [appdelegete.window makeKeyAndVisible];
    [UIView commitAnimations];



    // [FBLoginView class];




}

现在问题是一切正常但在加载应用程序视图后单击该按钮后,没有一个导航过程正常工作。我无法使用以下代码导航到任何其他屏幕..

 ViewController *HomeView=[[ViewController alloc]initWithNibName:@"ViewController" bundle:nil];
        [self.navigationController pushViewController:HomeView animated:YES];
        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:HomeView];

        [menuController setRootController:navController animated:YES];

我知道我在代码的某个地方犯了一些愚蠢的错误,所以任何人都可以指导我如何解决这个问题..

1 个答案:

答案 0 :(得分:1)

您的控制器层次结构看起来非常复杂,无法弄清楚您想要实现的目标。以下是我将首先进行的更新代码更改。

首先是App委托

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  LogInViewController *logInViewController = [[LogInViewController alloc]init];

  self.window.rootViewController = logInViewController;
  self.window.backgroundColor = [UIColor whiteColor];
  [self.window makeKeyAndVisible];

  return YES;
}

然后是按钮ibaction

- (IBAction)SignInCalled:(id)sender 
{
  ViewController *homeViewController = [[ViewController alloc]init];

  SlideTabViewController *rootController = [[SlideTabViewController alloc] initWithRootViewController:homeViewController];

  LeftSlideViewController    *leftController = [[LeftSlideViewController alloc] init];
  rootController.leftViewController = leftController;

  UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rootController];

  self.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
  [self presentViewController:navController animated:YES completion:NULL];

  // [FBLoginView class];
}