4

After using [UITableView deleteSections:withRowAnimation:] on a section which is out of view - the section header remains visible.

On this image, we see the visible part of the tableview

enter image description here

On the next image, we see the whole tableview - AISLE 2 is hidden until the user scrolls down, it contains only one row:

enter image description here

When I scroll down and delete the last row, AISLE 2 section header remains visible, even though I used deleteSections. if I delete a row from AISLE 1, the section header remains on the same place, and by scrolling down I can still see it.

Furthermore, when trying to scroll down so that AISLE 2 header is in the view, the UI acts as AISLE2 is NOT part of the tableview, and immediately scrolls me back up. Which means - this is a garbage view that is obviously not part of the table, since I removed it. for some reason, iOS doesn't remove this view, but de-associates it from the table.

Any ideas?

4

4 回答 4

0

你的数据来自哪里,你怎么知道一开始有多少个部分?我认为通过解释这一点可以轻松解决您的问题。

看起来您可能有一个多维nsmutablearray数据,其中每个索引都是一个通道,每个对象都包含该通道的产品?或者您可能为每个过道设置不同的阵列?

当您删除一个单元格时,只需检查剩余多少个单元格,然后调用[self.tableView reloadData];

对于(假设的)示例;

如果你有你的过道阵列:

NSMutableArray *aisleOne = [[NSMutableArray alloc] initWithObjects:@"Product1", @"Product2", nil];
NSMutableArray *aisleTwo = [[NSMutableArray alloc] initWithObjects:@"Product1", @"Product2", nil];
NSMutableArray *aisleThree = [[NSMutableArray alloc] initWithObjects:@"Product1", @"Product2", nil];
NSMutableArray *aisleFour = [[NSMutableArray alloc] initWithObjects:@"Product1", @"Product2", nil];

然后将它们添加到一个数组中:

NSMutableArray *aisleArray = [[NSMutableArray alloc] initWithObjects:aisleOne, aisleTwo, aisleThree, aisleFour, nil];

然后,在删除单元格时调用此代码。它将从aisleArray(需要全局定义)中删除所有空通道:

NSMutableArray *tempArray = [[NSMutableArray alloc] initWithArray:aisleArray];
for (int i=0; i<[tempArray count]; i++) {
    if ([[tempArray objectAtIndex:i] count] == 0) {
        [aisleArray removeObjectAtIndex:i];
    }
}
[self.tableView reloadData];

为此,这两种方法应该是:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [aisleArray count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [[aisleArray objectAtIndex:section] count];
}

(未经测试)

于 2013-01-24T09:53:56.817 回答
0

尝试[tableview reload]制作numberofsections为1。

于 2013-01-24T09:43:39.510 回答
0

几年后我面临同样的问题......删除最后一节不会从表格视图中删除最后一节标题。

然而,我注意到剩余的标题的框架正好低于正常的表格视图内容。因此,对我有用的解决方法(快速但您可以轻松地将其转换为 Objective C)是这样的:

DispatchQueue.main.async {
    let unwantedViews = self.tableView.subviews.filter{ $0.frame.minY >= self.tableView.contentSize.height}
    unwantedViews.forEach{ $0.isHidden = true }
}
于 2018-02-22T19:43:24.517 回答
0

只需获取该部分的表 haderview 并将其从它的超级视图中删除,并且 tableView 不管理它。

UIView *mysteriousView = [tableView headerViewForSection:indexPath.section];
[tableView deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationAutomatic];
[mysteriousView removeFromSuperview];

希望这可以帮助!

于 2015-09-17T14:44:50.120 回答