나는이 답변을 알고 있지만 불행히도 나는 InterfaceBuilder/Xcode에서 레이아웃을 허용하면서 여전히 다음과 같은 서브 클래 싱을 피할 수 있도록 테이블 뷰 셀 내의 필드를 찾기 위해 태그를 사용했다.
- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath {
static NSString *AttributeCellIdentifier = @"AttributeCell";
UITableViewCell *cell;
UILabel *label;
UITextField *value;
MyAttribute *a;
switch(indexPath.section) {
case ATTRIBUTES_SECTION:
cell = [tableView dequeueReusableCellWithIdentifier: AttributeCellIdentifier];
label = (UILabel *) [cell viewWithTag: 1];
value = (UITextField *) [cell viewWithTag: 2];
a = [attributeList objectAtIndex: indexPath.row];
label.text = a.label;
value.text = a.value;
break;
// Other sections...
}
return cell;
}
는하지만 내가 텍스트 필드가에있는 행에 대한 태그를 사용할 수 없음을 의미 내가 이렇게에 행 무엇을 볼 수있는 텍스트 필드에서 좌표를 사용 그래서 태그를 사용하는 대신 :.
- (void) textFieldDidEndEditing: (UITextField *) textField {
NSLog(@"Entering %s with %@", __func__, textField);
NSIndexPath *textFieldLocation = [self.tableView indexPathForRowAtPoint: [textField convertPoint:textField.bounds.origin toView: self.tableView]];
NSLog(@"- The textfield is in the cell at: %@", textFieldLocation);
if(textFieldLocation.section == ATTRIBUTES_SECTION) {
MyAttribute *a = [attributeList objectAtIndex: textFieldLocation.row];
a.value = textField.text;
}
}
텍스트 필드가 두 개 이상인 경우 셀에서 나는 태그 값을 사용하여 어느 것이 편집을 끝내는 지 알 수 있습니다.
심지어 어떤 보려면있는 tableview 인덱스를 반환하는 작은 도우미 메서드를 구축하는 스마트 수 있습니다 :이 필요한 코딩없이 범주에 넣어하고있는 tableview에 쉽게 사용할 수 할 수
- (NSIndexPath *) indexPathForView: (UIView *) view {
NSIndexPath *loc = [self.tableView indexPathForRowAtPoint: [view convertPoint: view.bounds.origin toView: self.tableView]];
return loc;
}
.
관련 코드를 게시하면 더 많은 답변을 얻을 수 있습니다. – sarnold