Skip to content

Instantly share code, notes, and snippets.

@keicoder
Last active January 1, 2016 06:48
Show Gist options
  • Save keicoder/8106965 to your computer and use it in GitHub Desktop.
Save keicoder/8106965 to your computer and use it in GitHub Desktop.
objective-c : UITextField 텍스트 유무에 따라 액션 버튼 활성화 판단
UITextField 텍스트 유무에 따라 액션 버튼 활성화 판단
- (BOOL)textField:(UITextField *)theTextField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
NSString *newText = [theTextField.text stringByReplacingCharactersInRange:range withString:string];
if ([newText length] > 0) {
self.doneBarButton.enabled = YES;
} else {
self.doneBarButton.enabled = NO;
}
return YES;
}
//simpler way to write the above method:
//self.doneBarButton.enabled = the result of the condition;
self.doneBarButton.enabled = ([newText length] > 0);
//( ) parentheses are not really necessary. so can also write it like this
self.doneBarButton.enabled = [newText length] > 0;
//relational operators in Objective-C
//> greater than
//< less than
//>= greater than or equal to <= less than or equal to
//== equal
//!= not equal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment