I have programmatically added a save and cancel button to my AddItemViewController which includes a textField and textView.
This is presented after a user taps a "+" button on the previous view.
The problem is; if no text is added to the text field I can still save. A blank item is added to the list. Also, because the buttons were created programmatically I can't use IB and I'm flying blind!
How can I require text to be input to enable the save function programmatically?
I've included what I've got so far.
Thanks!
This is presented after a user taps a "+" button on the previous view.
The problem is; if no text is added to the text field I can still save. A blank item is added to the list. Also, because the buttons were created programmatically I can't use IB and I'm flying blind!
How can I require text to be input to enable the save function programmatically?
I've included what I've got so far.
Thanks!
Code:
-(IBAction) save:(id)sender {
NSLog(@"Save pressed");
if (aTitle !=nil) {
[titleArray removeObject:aTitle];
self.aTitle = nil;
}
//create a new title dictionary for the new values
NSMutableDictionary* newTitle = [[NSMutableDictionary alloc] init];
[newTitle setValue:titleTextField.text forKey:NAME_KEY];
[newTitle setValue:titleDetailView.text forKey:TITLEINFO_KEY];
//add it to the master title array and release our reference
[titleArray addObject:newTitle];
[newTitle release];
NSSortDescriptor *nameSorter = [[NSSortDescriptor alloc] initWithKey:NAME_KEY ascending:YES selector:@selector(caseInsensitiveCompare:)];
[titleArray sortUsingDescriptors:[NSArray arrayWithObject:nameSorter]];
[nameSorter release];
[self dismissModalViewControllerAnimated:YES];
}