Подтвердить что ты не робот

Скрыть нижний колонтитул в UITableView

Я работал над скрывать footerview. Моя проблема в том, что у меня есть кнопка в нижнем колонтитуле, когда я нажимаю кнопку, одна секция будет добавлена ​​ниже в качестве последнего раздела, и кнопка тоже переместится на вновь созданный раздел, и теперь я хочу скрыть нижний колонтитул в предыдущем разделе таблицы после обновления разделов.

footerView.hidden = YES

Я использовал это в действии кнопки, но не работал.

4b9b3361

Ответ 1

Существует четыре решения. Они,

Решение 1:

tableView.sectionHeaderHeight = 0.0;
tableView.sectionFooterHeight = 0.0;

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger )section {
    return 1.0;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger )section {
    return 1.0;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger )section {
    return [[UIView alloc] initWithFrame:CGRectZero];
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger )section {
    return [[UIView alloc] initWithFrame:CGRectZero];
}

Решение 2:

Вы можете установить высоту нижнего колонтитула/заголовка через конструктор интерфейса под вкладкой размера.

Решение 3:

установите свойство contentInset.

self.tableView.contentInset = UIEdgeInsetsMake(-20, 0, -20, 0);

Используется, чтобы верх и низ касались края.

Решение 4:

реализовать ниже, установить значения в соответствии с вашим условием. 0.0 не принимаются. Нижнее значение должно быть 1.0.

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger )section {
    if(section == 0) {
       return 6;
    } else {
       return 1.0;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger )section {
    return 5.0;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger )section {
    return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger )section {
    return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
}

Ответ 2

Это должно сделать это

tableView.tableFooterView.hidden = YES;

Ответ 3

Это может сделать это путем реализации метода делегирования

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  return CGFLOAT_MIN;
}

Ответ 4

Если вы не используете пользовательские представления, верните nil из tableView:titleForFooterInSection: и 0 из tableView:heightForFooterInSection:.

@property(nonatomic, strong) NSString *footerTitle;
@property(nonatomic, assign) BOOL shouldHideFooter;
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
    return self.shouldHideFooter ? nil : self.footerTitle;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return self.shouldHideFooter ? 0 : UITableViewAutomaticDimension;
}

Ответ 5

Swift 3.0, который также удаляет надоедливую границу 1px между предыдущей ячейкой и следующим заголовком.

override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return CGFloat.leastNormalMagnitude
}

override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
    return nil
}