Cancel Button

Discussion in 'iPhone/iPad Programming' started by ljg93, Apr 21, 2011.

  1. macrumors member

    Joined:
    Mar 13, 2011
    #1
    hey everyone having trouble with this cancel button




    Code:
    - (void)viewDidLoad {
    	nameField.delegate = self;
    	descriptionField.delegate = self;
    	
    	self.navigationItem.title = @"New";
    	self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel 
    																						   target:self action:@selector(cancel:)] autorelease];
    	
        UIBarButtonItem *cancelButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStyleBordered target:self action:@selector(cancel)];
        self.navigationItem.leftBarButtonItem = cancelButtonItem;
        [cancelButtonItem release];
    	
        [super viewDidLoad];
    }
    
    
    

    my header is

    Code:
    
    @interface AddViewController : UIViewController <UITextFieldDelegate>
    
    
    {
    	
    	UITextField *nameField;
    	UITextField *descriptionField;
    	TableViewController *delegate;
    }
    @property (nonatomic, assign) TableViewController *delegate;
    @property (nonatomic, assign) IBOutlet UITextField *nameField;
    @property (nonatomic, assign) IBOutlet UITextField *descriptionField;
    
    
    
    
    - (void)save;
    - (void)cancel;
    
    
    

    shouldnt that be enough to make it work? A cancel button or a nav bar does not show up.
     
  2. macrumors newbie

    Joined:
    Jan 11, 2011
    #2
    Have you added the UIViewController AddViewController to a UINavigationController? You could do that in the AppDelegate, for instance.
     
  3. macrumors 603

    Joined:
    Aug 9, 2009
    #3
    1. You don't have a "cancel:" method in your class.
    You have "save" and "cancel", but no "cancel:".

    2. You're overwriting leftBarButtonItem only a few lines later, so it's unclear what this button is created for.
     

Share This Page