TableView에서 행을 삭제할 때 예외
-
20-09-2019 - |
문제
Deleterows 코드를 누를 때마다 업데이트 전후 행의 수가 동일해야한다는 예외가 있습니다. 공식 텍스트는 다음과 같습니다.
이유 : 유효하지 않은 업데이트 : 섹션 0의 유효하지 않은 행 수는 업데이트 (3) 이후 기존 섹션에 포함 된 행 수는 업데이트 (3), 플러스 또는 마이너스 이전에 해당 섹션에 포함 된 행 수와 같아야합니다. 해당 섹션에서 삽입 또는 삭제 된 행의 수 (0 삽입, 1 삭제).
내 코드는 다음과 같습니다.
public override void CommitEditingStyle (UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath)
{
if (editingStyle == UITableViewCellEditingStyle.Delete)
{
tableView.DeleteRows(new [] { indexPath }, UITableViewRowAnimation.Fade);
// Remove the step from the set of calculations
_calculation.Steps.RemoveAt(indexPath.Row);
}
}
해결책
반환 된 번호를 변경해야 할 것입니다
- (NSInteger)tableView:(UITableView *)aTableView numberOfRowsInSection:(NSInteger)section
용 indexPath.section
삭제 전보다 1 명입니다.
여기에서 답변 한대로 : UitableView 충돌에서 행을 삭제하십시오
다른 팁
내가 찾은 것은 TableView.deleterows (new [] {indexpath}, uitableviewrowanimation.fade)를 제거하는 것이 었습니다. 당신의 방법은 다음과 같이 보일 것입니다.
public override void CommitEditingStyle (UITableView tableView, UITableViewCellEditingStyle editingStyle, NSIndexPath indexPath)
{
if (editingStyle == UITableViewCellEditingStyle.Delete)
{
// Remove the step from the set of calculations
_calculation.Steps.RemoveAt(indexPath.Row);
tableView.reloadData();
}
}
제휴하지 않습니다 StackOverflow