Cancel Button

Discussion in 'iOS Programming' started by ljg93, Apr 21, 2011.

  1. ljg93 macrumors member

    Mar 13, 2011
    hey everyone having trouble with this cancel button

    - (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

    @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. Mac2011 macrumors newbie

    Jan 11, 2011
    Have you added the UIViewController AddViewController to a UINavigationController? You could do that in the AppDelegate, for instance.
  3. chown33 macrumors 604

    Aug 9, 2009
    on the Western Slopes, with E. A. Poe
    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