2012-01-03 2 views
1

내 애플리케이션에서 편집 변경 사항을 textFieldDidEndEditing:에 적용하면 UITextField가 어느 셀에 있는지를 추적 할 수 있어야합니다. 이를 위해 방금 셀의 텍스트 필드에 태그 속성을 tableview:cellForRowAtIndexPath:으로 설정했습니다.행이 이동 된 후 UITableViewCell 태그 속성을 업데이트하십시오.

셀을 이동하면 약간의 문제가 발생합니다. 예를 들어 아래쪽 셀을 맨 위로 이동하고 맨 아래에있는 셀을 삭제 한 다음 상단에 배치 한 셀을 편집하려고하면 태그 속성이 여전히 8이기 때문에 내 응용 프로그램이 중단됩니다 (또는 다른 번호),하지만 내 데이터 소스에 많은 요소가 없습니다.

나는 (BookmarkTextEntryTableViewCell *)[[self tableView] cellForRowAtIndexPath:toIndexPath] 전에이 행을 이동했다 셀을 반환하기 때문에 그러나,이 작동하지 않습니다 tableView:moveRowAtIndexPath:toIndexPath:

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath { 
    NSString *siteToMove = [[sites objectAtIndex:[fromIndexPath row]] retain]; 

    [sites removeObjectAtIndex:[fromIndexPath row]]; 
    [sites insertObject:siteToMove atIndex:[toIndexPath row]]; 

    if ([toIndexPath section] == 1) { 
     [[(BookmarkTextEntryTableViewCell *)[[self tableView] cellForRowAtIndexPath:toIndexPath] textField] setTag:[toIndexPath row]]; 
    } 
} 

에 태그를 업데이트하여이 문제를 해결하기 위해 노력했다.

당신의 - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath 방법, 당신은 당신이 테이블에 파단으로 추가 한 수있는 모든 UITextField의 반복 한 다음 확인

for (UIView* subview in [[self tableView] subviews]) { 
if ([subview isKindOfClass:[UITextField class]]) { 
    if(subview.tag==oldTag){ 
    subview.tag = newTag; 
    break; 
    } 
} 
} 

편집 된 직후 새 태그 설정할 수 있습니다에서

답변

1

: 다시 생각을 나머지 셀의 태그를 모두 재설정하는 경우에 대비하여 테이블 데이터를 다시로드 할 수 있습니다.

관련 문제