I am trying to get my app to switch views after a user clicks a ‘submit’ button.
This is what I have so far:
viewA.h
@property (nonatomic, retain) RootViewController *root;
viewA.m
-(void)switchToLogView{
NSLog(@"switch to log view");
UIViewController <SubstitutableDetailViewController> *detailViewController = nil;
LogDetailViewController *newDetailViewController = [[LogDetailViewController alloc] initWithNibName:@"LogDetailViewController" bundle:nil];
detailViewController = newDetailViewController;
// Update the split view controller's view controllers array.
NSArray *viewControllers = [[NSArray alloc] initWithObjects:self.navigationController, detailViewController, nil];
root.splitViewController.viewControllers = viewControllers;
// Dismiss the popover if it's present.
if (root.popoverController != nil) {
[root.popoverController dismissPopoverAnimated:YES];
}
// Configure the new view controller's popover button (after the view has been displayed and its toolbar/navigation bar has been created).
if (root.rootPopoverButtonItem != nil) {
[detailViewController showRootPopoverButtonItem:self.root.rootPopoverButtonItem];
}
[detailViewController release];
}
The splitViewController , popoverController , and rootPopoverButtonItem are all declared in my RootViewController class (I started with the apple sample code).
The code builds fine, but when I make the call to the method, nothing happens.
I just had to learn how to do this recently too. I wanted an “about” button on my screen that would flip into another view when the user clicked the button, then flipped back to my original view when they clicked the “done” button.
I think you’re over-complicating it. Here’s the code I have to bring up the About View.
Obviously, don’t forget to import it in your header:
#import <AboutViewController.h>And my code to bring back the original view (aka hide the about view) is:
[self.parentViewController dismissModalViewControllerAnimated:YES];