uitextfield를 선택하는 방법?
-
05-07-2019 - |
문제
UitableView 내에서 사용자의 사용자 이름을 편집하고 싶습니다. 나는 UitableViewCell에 uitextfield를 추가했는데 이것은 매우 잘 작동하는 것 같습니다. 그러나 사용자가 셀 외부에서도 셀에 닿으면 편집 할 것으로 예상됩니다.
텍스트 필드를 프로그래밍 방식으로 선택하려면 어떻게해야합니까?
코드는 다음과 같습니다.
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
userName.selected = TRUE;
}
해결책
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cellSelected = [tableView cellForRowAtIndexPath: indexPath];
UITextField *textField = [[cellSelected.contentView subviews] objectAtIndex: 0];
[textField becomeFirstResponder];
[tableView deselectRowAtIndexPath: indexPath animated: NO];
}
이것은 어떤 uitextfield 객체가 어떤 셀인지 알 수있는 더 빠른 방법이 없으며 Uitextfield가 첫 번째 하위 뷰가 될 것임을 확실히 알고 있다고 가정합니다.
또한 [Textfield isfirstresponder]를 확인하고 싶을 수도 있습니다. 이미 FIRSTRESPENDER로 만들 수는 없습니다. 그래도 이것은 필요하지 않을 수 있습니다.
제휴하지 않습니다 StackOverflow