나는 무엇 영업 이익은 이해하려고하는 것은 사용자가 각 필드에 데이터를 입력 한 일단의 UITextField 값에 액세스하는 방법을 생각합니다. @willcodejavaforfood가 제안한대로 셀을 만들 때 사용할 수 없습니다.
저는 양식을 구현하여 가능한 한 사용자 편의를 도모하려고 노력했습니다. 그것은 가능하지만 당신이 가지고있는 UITableViewCells/UITextFields의 수에 따라 꽤 복잡하게 될 수 있다는 것을 알아 두십시오. 귀하의 질문에 다시에 첫째
:의 UITextField의 값을 액세스하는 : 나는도를 사용
- (void) textFieldDidEndEditing:(UITextField *)textField {
NSIndexPath *indexPath = [self.tableView indexPathForCell:(CustomCell*)[[textField superview] superview]]; // this should return you your current indexPath
// From here on you can (switch) your indexPath.section or indexPath.row
// as appropriate to get the textValue and assign it to a variable, for instance:
if (indexPath.section == kMandatorySection) {
if (indexPath.row == kEmailField) self.emailFieldValue = textField.text;
if (indexPath.row == kPasswordField) self.passwordFieldValue = textField.text;
if (indexPath.row == kPasswordConfirmField) self.passwordConfirmFieldValue = textField.text;
}
else if (indexPath.section == kOptionalSection) {
if (indexPath.row == kFirstNameField) self.firstNameFieldValue = textField.text;
if (indexPath.row == kLastNameField) self.lastNameFieldValue = textField.text;
if (indexPath.row == kPostcodeField) self.postcodeFieldValue = textField.text;
}
}
:
1) 뷰 컨트롤러가 <UITextFieldDelegate>
2) 다음과 같은 메소드를 구현합니다 비슷한 구문으로 현재 수정 된 입력란이 표시되는지 확인하십시오.
- (void) textFieldDidBeginEditing:(UITextField *)textField {
CustomCell *cell = (CustomCell*) [[textField superview] superview];
[self.tableView scrollToRowAtIndexPath:[self.tableView indexPathForCell:cell] atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
}
,210
그리고 마지막으로, 당신은 비슷한 방법으로 textViewShouldReturn:
을 처리 할 수
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
NSIndexPath *indexPath = [self.tableView indexPathForCell:(CustomCell*)[[textField superview] superview]];
switch (indexPath.section) {
case kMandatorySection:
{
// I am testing to see if this is NOT the last field of my first section
// If not, find the next UITextField and make it firstResponder if the user
// presses ENTER on the keyboard
if (indexPath.row < kPasswordConfirmField) {
NSIndexPath *sibling = [NSIndexPath indexPathForRow:indexPath.row+1 inSection:indexPath.section];
CustomCell *cell = (CustomCell*)[self.tableView cellForRowAtIndexPath:sibling];
[cell.cellTextField becomeFirstResponder];
} else {
// In case this is my last section row, when the user presses ENTER,
// I move the focus to the first row in next section
NSIndexPath *sibling = [NSIndexPath indexPathForRow:kFirstNameField inSection:kOptionalSection];
MemberLoginCell *cell = (MemberLoginCell*)[self.memberTableView cellForRowAtIndexPath:sibling];
[cell.cellTextField becomeFirstResponder];
}
break;
}
...
}
출처
2010-12-07 11:02:18
Rog
건배 Rog, 내 Mac으로 돌아 가면 그걸 시험해 보겠습니다. 나는 애플이 어떻게하는지 궁금해하는데, 셋팅 앱처럼 나는 이것보다 조금 더 똑바로/더 깨끗하게 될 줄 알았다. 아마 그들은 완전히 다른 방식으로 코드를 작성했을 것입니다. – Darthtong