Switching Views - view is empty.

Discussion in 'iOS Programming' started by natanavra, Dec 28, 2008.

  1. natanavra macrumors newbie

    Dec 26, 2008
    Hi, I'm kinda new here so no flaming or anything please.
    anyways, I have a problem I am making a game and as I designed it, I have a splash screen (which is ok) after a few secs The view flips to the main menu.
    In the main menu I have a few button (arcade, help, statistics and about), I decided to create the about window first (easiest...).
    created an about.nib, and aboutview.m/h and aboutController.m/h, linked everything through IB and added these several lines of code:

    - (void)loadAboutView {
    aboutViewController *viewController = [[aboutViewController alloc] initWithNibName:mad:"about" bundle:nil];
    self.about = viewController;
    [viewController release];
    self.aboutNavigationBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0, 0.0, 320.0, 35.0)];
    self.aboutNavigationBar.barStyle = UIBarStyleBlackOpaque;
    UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:mad:selector(toggleAbout)];
    buttonItem.title = @"Back";
    UINavigationItem *navigationItem = [[UINavigationItem alloc] initWithTitle:mad:"About"];
    navigationItem.rightBarButtonItem = buttonItem;
    [aboutNavigationBar pushNavigationItem:navigationItem animated:NO];
    [navigationItem release];
    [buttonItem release];

    - (IBAction)toggleAbout {
    if(about == nil){
    [self loadAboutView];
    UIView *mainView = about.view;
    UIView *flipsideView = flipsideViewController.view;
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:2.0];
    [UIView setAnimationTransition:([mainView superview] ? UIViewAnimationTransitionFlipFromRight : UIViewAnimationTransitionFlipFromLeft) forView:self.view cache:YES];

    if ([mainView superview] != nil) {
    [flipsideViewController viewWillAppear:YES];
    [about viewWillDisappear:YES];
    [mainView removeFromSuperview];
    [self.view addSubview:flipsideView];
    [about viewDidDisappear:YES];
    [flipsideViewController viewDidAppear:YES];

    } else {
    [about viewWillAppear:YES];
    [flipsideViewController viewWillDisappear:YES];
    [flipsideView removeFromSuperview];
    [self.view insertSubview:aboutNavigationBar aboveSubview:mainView];
    [flipsideViewController viewDidDisappear:YES];
    [mainViewController viewDidAppear:YES];
    [UIView commitAnimations];

    in the main menu when I click the about button the View flips into an empty view... any ideas?
    if anyone can point out the mistake or give an ex. to a right piece of code - will be most appriciated.
    ~Thanks in advance.
  2. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    You main menu is your main view, right? So why are you setting your mainView variable to about.view? I would think you'd want about.view to be your flipsideView.
  3. natanavra thread starter macrumors newbie

    Dec 26, 2008
    If you could - please close this topic, I made a new app and everything is super cool!
    I guess the problem was that I didn't link the views in the interface builder - not sure about it.
    anyways I'm cool - you can close this topic.

Share This Page