Quote:
Originally Posted by Duncan C
Sure.
Add a delegate of the UITextField.
Implement the UITextFieldDelegate method textField:shouldChangeCharactersInRange:replacemen tString:
This method gets called every time the user types a character or otherwise changes the text in the field.
In that routine, check to see if the text of the text field has a length of zero. IF yes, disable your save button. If no, enable the save button. (always return true unless you want to prohibit the change the user tries to make)
You might need to call yourself with performSelector:withObject:afterDelay:0 and check the text length in the method that you call, to give the system a chance to change the text of the text field after each edit. I haven't tried the approach I'm describing, but it should work.
|
I've added the ...shouldChangeCharactersInRange method... and it works.
As an example !([newString length] > 6); limits character to six
Would you explain how to have the code NOT accept less than one or 0 prior to enabling the save button?
The second question is: how do I disable the save button to start with.
The code below is what I'm using.
-(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];
}
-(IBAction) cancel

id)sender {
NSLog (@"Cancel pressed");
[self dismissModalViewControllerAnimated:YES];
}