내 앱에서 아주 이상한 동작이 나타났습니다. 가장 단순한 시나리오에서 문제를 재현했습니다.행이 삭제되면 버튼이 맞춤 섹션 헤더보기에 추가됩니다.
NSMutableArray *data;
- (void)viewDidLoad {
[super viewDidLoad];
data = [[NSMutableArray arrayWithObjects:@"1", @"2", @"3", nil] retain];
}
- (UIView *)tableView:(UITableView *)aTableView viewForHeaderInSection:(NSInteger)section {
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, self.view.frame.size.width, 32.0)];
header.backgroundColor = [UIColor lightGrayColor];
[header addSubview:self.button];
return header;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[data removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop];
}
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return data.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
cell.textLabel.text = [data objectAtIndex:indexPath.row];
return cell;
}
- (void)dealloc {
[super dealloc];
}
행을 삭제할 때마다 문제가 재현됩니다. 내 머리글의 버튼이 사라집니다! 이것은 내가 사용하는 rowAnimation의 유형에 관계없이 발생합니다. 헤더가 스크롤되도록 테이블을 위로 스크롤하면; 헤더가 반환되면 버튼이 반환됩니다. 버튼은 xib 파일에 생성됩니다.
나는 두 가지 방법 중 하나에 해결할 수 있습니다 삭제 후있는 tableView의 데이터를 다시로드
- ; 삭제 애니메이션이 먼저 완료되도록 지연 시키십시오.
interfaceBuilder 대신 viewForHeaderInSection에 버튼을 생성합니다.
나는 여기서 무슨 일이 일어나고 있는지 알고 싶습니다. 버튼은 어디에 있습니까? 행을 삭제할 때 viewForHeaderInSection이 호출됨을 확인했습니다.
편집 내가 만들거나 버튼을 삭제할 때, 나는 특정 설정하고 ... 버튼을 대신 XIB에서의, viewForHeader에서 생성되도록 나는 그것을 변화 시도,하지만 다른 이상한 문제의 원인 제목과 같은 속성 및 테이블에있는 항목의 수에 따라 활성화됩니다. 표의 마지막 행을 삭제할 때 화면에서 버튼을 스크롤하고 다시 켜기 전까지는 텍스트로 업데이트 된 것을 볼 수 없습니다.
tableView : cellForRowAtIndexPath에서 테이블 셀을 재사용하지 않는 이유는 무엇입니까? –
실제 코드에서 표 셀을 재사용하고 있습니다. 여기에 코드를 게시하기 위해 가능한 한 간결하게 작성하고 동일한 문제가있는 코드를 게시했습니다. xib 파일에 heightForHeader를 정의하고 있습니다. – GendoIkari
내 편집/추가를 참조하십시오. –