Last active
January 1, 2016 06:48
-
-
Save keicoder/8106965 to your computer and use it in GitHub Desktop.
objective-c : UITextField 텍스트 유무에 따라 액션 버튼 활성화 판단
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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