3

i'm playing around with the great library ZUUIRevealController. However, I can't program it so the user are able to tap a cell in the rearcontroller. The rearcontroller should then go away and display a new viewcontroller in the front view.

I've setup my project like this:

    VGViewController *frontViewController;
RevealController *rearViewController;

frontViewController = [[VGViewController alloc] initWithNibName:@"VGViewController" bundle:nil];

self.navigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];

rearViewController = [[RevealController alloc] initWithNibName:@"RevealController" bundle:nil];

ZUUIRevealController *revealController = [[ZUUIRevealController alloc] initWithFrontViewController:self.navigationController rearViewController:rearViewController];

[frontViewController release];
[rearViewController release];

self.window.rootViewController = revealController;
[revealController release];
[self.window makeKeyAndVisible];
return YES;

I hope someone can help me! :D

Jonas
  • 55
  • 1
  • 5

1 Answers1

4

glad you found a liking in the library.

Your project seems to be setup correctly if I'm not missing anything, although logically I'm not able to follow how the rearViewController <=> RevealController but that's okay I guess.

To answer your question: In order to display a different frontViewController by, say tapping on a cell in the rearViewController you need to trigger this piece of code in the appropriate method (say: tableView:didSelelctRowAtIndexPath:)

// RearViewController.m file in some method:
// - Let's grab a reference to the revealController first:
ZUUIRevealController *revealController = [self.parentViewController isKindOfClass:[ZUUIRevealController class]] ? (ZUUIRevealController *)self.parentViewController : nil;

// Check if we're not attempting to swap the current FrontViewController for exactly the same controller over again...
if (![revealController.frontViewController isKindOfClass:[NewFrontViewController class]])
{
        NewFrontViewController *newFrontViewController;

        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
        {
            newFrontViewController = [[NewFrontViewController alloc] initWithNibName:@"NewFrontViewController_iPhone" bundle:nil];
        }
        else
        {
            newFrontViewController = [[NewFrontViewController alloc] initWithNibName:@"NewFrontViewController_iPad" bundle:nil];
        }

        UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:newFrontViewController];
        [newFrontViewController release];
        [revealController setFrontViewController:navigationController animated:NO];
        [navigationController release];
}

What this piece of code does is, it grabs a reference to the rearViewControllers parent (which should be the revealController), and assigns a new frontViewController instance to it by calling [revealController setFrontViewController:navigationController animated:NO];

Hope this solves your problem :-)

pkluz
  • 4,871
  • 4
  • 26
  • 40
  • Thanks for the response. I can not get it to work. I have four elements in my array and when i use the above posted code nothing happens. In a tableview i can check if the tapped cells text is equal to a string and then perform the navigation based on that. Can i do something simular here? – Jonas Feb 23 '12 at 17:30
  • Have you looked at the updated example project I provide with the library two weeks ago? I set up a table in the rearView and it swaps the frontViewController for a different one. - But yes of course you can check if the text matches something you want and then trigger an action. - The idea is basically really simple and your problem doesn't seem to lie within the library.All you need to do is create a new viewcontroller and call `[revealController setFrontViewController:newViewController animated:NO]`.The same as if you'd call `[self.navigationController pushViewController:XXX animated:YES];` – pkluz Feb 23 '12 at 17:42
  • Glad you figured it out. Don't forget to accept the answer then:) – pkluz Feb 24 '12 at 00:18