일부 행을 UITableView
에 표시하고 섹션의 헤더에있는 행 수를 표시하지만 행을 삭제하면보기가 매우 이상하게 보임으로 인해 애니메이션이 삭제됩니다 . 내가 뭔가를 놓친다면 내 코드를 살펴 보라.UITableView에서 행 제거 및 섹션 헤더 업데이트
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[[UIView alloc]init] autorelease];
view.backgroundColor = [UIColor colorWithRed:(249.0/255.0) green:(249.0/255.0) blue:(249.0/255.0) alpha:1];
UILabel *label = [[[UILabel alloc]initWithFrame:CGRectMake(15, 15, 100, 15)] autorelease];
[label setTextColor:[UIColor colorWithRed:0.56 green:0.56 blue:0.58 alpha:1.0]];
[label setFont:[UIFont fontWithName:@"HelveticaNeue" size:12]];
label.text = @"SELECTED ACCOUNTS (";
NSString *numberOfAccounts = [NSString stringWithFormat:@"%li)", (unsigned long)[self->_selectedAccounts count]];
if([self->_selectedAccounts count])
label.text = [label.text stringByAppendingString:numberOfAccounts];
[view addSubview:label];
[view sizeToFit];
[label sizeToFit];
return view;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0)
{
NSMutableArray *selectedAcc = [[NSMutableArray alloc] initWithArray:self->_selectedAccounts];
[selectedAcc removeObjectAtIndex:indexPath.row];
self->_selectedAccounts = selectedAcc;
[self->_MyTableView beginUpdates];
[self->_MyTableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationTop];
[self->_MyTableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationNone];
[self->_MyTableView endUpdates];
}
}
감사합니다 도움이 될 것입니다하지만 난 내 코드를 가진 유일한 문제는 그것이 정상적으로 애니메이션되지 않는 것입니다 헤더 행을 삭제하고 업데이트 할 수 있어요 수 내. 행을 삭제하고 헤더를 업데이트하는 두 줄은 다음과 같습니다. '[self -> _ MyTableView deleteRowsAtIndexPaths : @ [indexPath] withRowAnimation : UITableViewRowAnimationTop]; // [self -> _ MyTableView reloadSections : [NSIndexSet indexSetWithIndex : indexPath.section] withRowAnimation : UITableViewRowAnimationNone]; 그래서이 경우에는 섹션 헤더를 업데이트하는 코드에 주석을 달았으므로 이제는 애니메이션이 좋습니다. –
확인. 내 대답에 그 링크를 읽으십시오 .. 그 또한 당신의 문제에 도움이 ... –
예 나는 당신이 준 링크에서 이해하려고합니다. –