일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
- backspace
- color
- 아이튠즈
- sqlSession
- KVO_IS_RETAINING_ALL_OBSERVERS_OF_THIS_OBJECT_IF_IT_CRASHES_AN_OBSERVER_WAS_OVERRELEASED_OR_SMASHED
- mysql
- googlemap
- 색상 변경
- 실행
- DELETE
- UITextField
- Cluster
- beanCreationException
- mybatis
- 삭제
- NoClassDefFoundError
- delete button
- 삭제버튼
- KVO
- command not found
- IPA
- Exception
- dataSource
- Detect
- 단축키
- Drawer
- Query
- bash
- api19
- itunes
- Today
- Total
BlueAroma
UITextField - 키보드에서 삭제 버튼 클릭 여부 인식하기 본문
UITextField 를 카테고리 한 후 Private한 함수를 하나 override 함.
( 앱스토어 검수에서 문제가 생기지 않았다고 함 )
UITextField+delete.h
@interface UITextField(delete)
@end
UITextField+delete.m
@implementation UITextField(delete)
- (BOOL)keyboardInputShouldDelete:(UITextField *)textField {
NSInteger location = [textField text].length - 1;
if ([self.delegate respondsToSelector:@selector(textField:shouldChangeCharactersInRange:replacementString:)]) {
[self.delegate textField:self shouldChangeCharactersInRange:NSMakeRange(location, 1) replacementString:@""];
}
return YES;
}
@end
활용하기
Delete 버튼 인식할 UITextField 는 Delegate를 연결한다.
ViewController.m
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if(range.length == 1 && string.length == 0) {
//- backspace
}
return YES;
}
'내맘대로 프로그래밍 > iOS' 카테고리의 다른 글
[Crash] KVO_IS_RETAINING_ALL_OBSERVERS_OF_THIS_OBJECT_IF_IT_CRASHES_AN_OBSERVER_WAS_OVERRELEASED_OR_SMASHED (0) | 2017.11.09 |
---|---|
[iOS] iTunes를 이용한 iPad 설치 ( iOS11 , iTunes 12.7 이후) (1) | 2017.09.26 |