I have a UITextView and i would like to limit the number of characters a user can input. i have also tried to display a warning if the textfield is empty but to no luck.
textview.h @property (nonatomic,strong) IBOutlet UITextView *textField; @property (nonatomic, retain) NSString *userText; textview.m - (IBAction)next:(id)sender { self.userText = self.textField.text; if ([self.textField.text length] == 0) { UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error!" message:@"Enter some text" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alertView show]; } } here is the text limit method that does not seem to work,
- (BOOL)textView:(UITextView *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{ if(range.length + range.location > textField.text.length) { return NO; } else { NSUInteger newLength = [textField.text length] + [string length] - range.length; return newLength <= 70; return (textField.text.length <= 70); } }