Solution to the strings that are empty and spaces in UITextField and UITextView in IOS
When writing some pages with UITextField and UITextView declared properties, such small bugs often occur, that is, you can pass or store values with empty values or spaces. Here are some small solutions:
eg:
A property is declared here, for example
@property (nonatomic, strong) UITextField *titlefield;
When empty:
if(_titlefield.text == nil){ //Perform some warning operations} if (_titlefield.text == NULL) { //Perform some warning operations } if ([_titlefield.text isKindOfClass:[NSNull class]]) { //Perform some warning operations } When it is a space: if ([[_titlefield.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]length] == 0) { //Perform some warning operations }
Thank you for reading, I hope it can help you. Thank you for your support for this site!