Question

I found this code to display a modal view:

- (void)add:(id)sender {
   // Create the root view controller for the navigation controller
   // The new view controller configures a Cancel and Done button for the
   // navigation bar.
   RecipeAddViewController *addController = [[RecipeAddViewController alloc]
                       initWithNibName:@"RecipeAddView" bundle:nil];
   addController.delegate = self;

   // Create the navigation controller and present it modally.
   UINavigationController *navigationController = [[UINavigationController alloc]
                             initWithRootViewController:addController];
   [self presentModalViewController:navigationController animated:YES];


   // The navigation controller is now owned by the current view controller
   // and the root view controller is owned by the navigation controller,
   // so both objects should be released to prevent over-retention.
   [navigationController release];
   [addController release];
}

My question is how do I implement this code (I'm going to place it in a buttonPress method)

Do I need to define anything in my header file? The bit that confuses me is that apple on provides this and no header file so i cant tell if anything should be there?

The code refers to RecipieAddViewController what do I repleace this with, "UIViewController" ?

What do I put as the delegate in the headerfile ? do I need to set this up anywhere else ? like with a property?

Is there anything else I need to do once I have copid this code in my buttonPress method to make it work?

Thanks and sorry for all the questions.

Was it helpful?

Solution

My question is how do I implement this code (I'm going to place it in a buttonPress method)

Define the method as an IBAction like -(IBAction)add:(id)sender and in interface builder bind a button's touch up inside event to the view controller object's add: action outlet.

Do I need to define anything in my header file? The bit that confuses me is that apple on provides this and no header file so i cant tell if anything should be there?

Nope. All this stuff needs is UIKit.h You usually need to change your header to add methods, add instance variables, or include custom classes. You may need a #import RecipeAddViewController.h somewhere (in your header or your implementation file) in order to use that class, however. This is true for any custom class you write that you want to use in another file.

The code refers to RecipieAddViewController what do I repleace this with, "UIViewController"?

Replace that with the view controller class you want to push. UIViewController itself is rarely useful naked. It's made to subclassed. So you create a new class that inherits from UIViewController, import it's header, create and instance of it, and push it on the navigation controller.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top