PDA

View Full Version : Cancel Button




ljg93
Apr 21, 2011, 05:48 PM
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.



Mac2011
Apr 23, 2011, 08:07 AM
Have you added the UIViewController AddViewController to a UINavigationController? You could do that in the AppDelegate, for instance.

chown33
Apr 23, 2011, 12:05 PM
- (void)viewDidLoad {
...
self.navigationItem.title = @"New";
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel

target:self action:@selector(cancel:)] autorelease];

...

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.