0

My situation is that I have a Primary View Controller (UIViewController in PrimaryViewController.h .m) that contains a UIButton. When pressed, a second View Controller (UINavigationController) is displayed, the general idea is to press a "settings" button and for a navigation view to pop up and allow the user to amend their settings.

I have been able to do this, but I am not entirely confident with my method. Inside the Primary View Controller I have added a Navigation Controller and linked it as an outlet inside the Primary controller. Then when the button is pressed, the function, showSettings is called:

- (IBAction)showSettings {
    [self presentModalViewController:navigationViewController animated:YES];
}

Similarly a hideSettings is called to close. Whilst this does work, I'm not sure I've done this in the best or correct way. I did previously try to create the Navigation Controller in the MainWindow.xib and link it with the App Delegate, however I ran into a problem where I needed to call/display this controller in the PrimaryViewController.m implementation file and couldn't work out how to do this (i.e. how to perform [super addSubview:]; outside the App Delegate class).

I could use what I have now, but would like to know the alternate method to doing this, primarily because I am not happy with the transition animation for Modal View Controllers and would rather use a flip animation.

Thanks in advance!

sooper
  • 5,991
  • 6
  • 40
  • 65
  • Right, instead of using `presentModalViewController` I'm simply using `addSubview:navigationViewController.view`. This works, but rather strangely the view is placed about 20 pixels below the main window and I can see the view underneath it. – sooper Dec 12 '11 at 17:28
  • Had to adjust the frame and set the Layout to "Wants full screen" in Interface Builder. – sooper Dec 12 '11 at 17:40

2 Answers2

0

Here is what I would do: 1. Create a separate class file for a navigation controller. Say call it MyNavigateController. You can add this to your YourAppAppDelegate. MyNavigateController.h looks like this:

@interface MyNavigateController : UIViewController 
{
    UINavigationController *navController;
}
@property (nonatomic, retain) IBOutlet UINavigationController *navController;
@end

MyNavigateController.m looks like this for the viewDidLoad method:

- (void)viewDidLoad
{
[self.view addSubview:self.navController.view];
}

For MyNavigateController.xib, use drag a Navigation Controller object and assign it to your PrimaryViewController class.

In your PrimaryViewController class

- (IBAction)showSettings {
    ChildViewController *childViewController = [ChildViewController alloc]initWithNibName:@"ChildViewController" bundle:nil];
//childViewController.ivarsifany = ....  //optionaly assign values to ivars etc.
    [self.navigationController pushViewController:childViewController
                                         animated:YES];
}
user523234
  • 14,323
  • 10
  • 62
  • 102
  • Do you mean `MyNavigateController *childViewController = [MyNavigateController alloc]initWithNibName:@"ChildViewController" bundle:nil];`? and where have you declared `navigationController` for `self.navigationController`? – sooper Dec 12 '11 at 18:29
  • No... ChildViewController is the whatever child view controller class that you want to present from PrimaryViewController. It can be another UIViewController, etc. self.navigationController resulted from the step that I mentioned above: "For MyNavigateController.xib, use drag a Navigation Controller object and assign it to your PrimaryViewController class." – user523234 Dec 12 '11 at 22:01
0

If your only problem is the specific transition animation for presentModalViewController:, then you can just change the transition type. There are a few different given transition animations, like this:

- (IBAction)showSettings {
    [navigationViewController setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
    [self presentModalViewController:navigationViewController animated:YES];
}

There are more transition styles, such as UIModalTransitionStyleCoverVertical, UIModalTransitionStyleCrossDissolve, and UIModalTransitionStylePartialCurl.

gurooj
  • 2,100
  • 4
  • 21
  • 25