search

Home  >  Q&A  >  body text

ios - UItableview cell 第一个cell上面的距离怎么变小

试了用-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section方法,但是不知为什么并没有什么改变。。还有什么办法吗?或者我上面的方法可能问题出在哪些地方

PHPzPHPz2891 days ago446

reply all(5)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 17:58:16

    return 0.001 has no effect?

    reply
    0
  • 怪我咯

    怪我咯2017-04-17 17:58:16

    If you return 0 in this method;

    In fact, the default value is still displayed

    So you can try return 1; or a smaller number

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 17:58:16

    If I understand correctly, you want to change the distance from the first Cell to the top. You can fill an empty UIViewtableHeaderView and then control it through the Frame Height of this View.

    UIView *tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 1, 10)];    // 这里 10 就是你想要的高度
    tableView.tableHeaderView = tableHeaderView;

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 17:58:16

    If you just want to change the distance from the first cell to the top, the simplest, direct and crude way is to reserve the space you want between the top of your tableView and the top of the parent view (that is, the so-called above the first cell distance), this can

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 17:58:16

    I don’t know what the directory level of your view is. To set the height of the header, you must first have a header.

    //swift
    // 返回header的高度
    override func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
        return 5
    }
    // 在header中添加一个视图
    override func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
        let view = UIView()
        view.backgroundColor = UIColor.redColor()
        return view
    }

    reply
    0
  • Cancelreply