UITableView不会让我滚动

时间:2013-07-21 01:02:39

标签: ios objective-c uitableview

我无法在顶部使用UIView获取此tableView以正常工作。会发生的情况是,单元格在附件视图中有一个复选标记,在viewDidLoad中我希望所有单元格都显示该复选标记。所以我“点击”代码中的Select all按钮。

[self.selectToggleButton sendActionsForControlEvents:UIControlEventTouchUpInside];

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

enter image description here

pragma mark - 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;
}

0 个答案:

没有答案