0

我无法让这个UIView顶部有 a 的 tableView 正常工作。发生的情况是单元格在其附件视图中有一个复选标记,并且viewDidLoad我想让所有单元格都显示该复选标记。所以我“点击”Select all代码中的按钮。

[self.selectToggleButton sendActionsForControlEvents:UIControlEventTouchUpInside];

但是当我这样做时,它不会让我滚动tableView,或者它会滚动 - 但它不会让我滚动到底部,因为它会不断跳回初始位置,直到我点击Select all按钮,然后它工作正常。

在此处输入图像描述

杂注标记 - IBActions

- (IBAction)selectAllRows:(id)sender {
    
    [self.selectedSongs removeAllObjects];
    [self.selectedCells removeAllObjects];
    NSUInteger numberOfSections = [self.tableView numberOfSections];
    for (NSUInteger s = 0; s < numberOfSections; ++s) {
        NSUInteger numberOfRowsInSection = [self.tableView numberOfRowsInSection:s];
        for (NSUInteger r = 0; r < numberOfRowsInSection; ++r) {
            NSIndexPath *idxPath = [NSIndexPath indexPathForRow:r inSection:s];
            [self.selectedCells addObject:idxPath];
            [self.selectedSongs addObject:self.allSongs[idxPath.row]];
        }
    }
    [self.tableView reloadData];
}



- (IBAction)deselectAll:(id)sender {
    [self.selectedSongs removeAllObjects];
    [self.selectedCells removeAllObjects];
    [self.tableView reloadData];
}


- (IBAction)toggleAll:(UIButton *)sender
{
    if ([self.allSongs count] == [self.selectedSongs count]) {
                [sender setTitle:@"Select all" forState:UIControlStateNormal];
        [self deselectAll:sender];
    } else {
        [sender setTitle:@"Deselect all" forState:UIControlStateNormal];
        [self selectAllRows:sender];
    }
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.allSongs.count;
}
4

0 回答 0