Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ljg93

macrumors member
Original poster
Mar 13, 2011
98
0
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.
 
Have you added the UIViewController AddViewController to a UINavigationController? You could do that in the AppDelegate, for instance.
 
Code:
- (void)viewDidLoad {
...	
	self.navigationItem.title = @"New";
	self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel 

target:self action:[COLOR="Red"]@selector(cancel:)[/COLOR]] 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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.