UITableView: the proper way to display a separator for the last cell

后端 未结 14 1020
礼貌的吻别
礼貌的吻别 2020-12-29 02:23

The question is what\'s the right-most way to display a separator in the last cell in a table/section.

Basically this is what I am after.

14条回答
  •  南方客
    南方客 (楼主)
    2020-12-29 03:07

    I just found something that works for me. In a few words: give your UITableView a tableFooterView and set its frame's height to 0. This makes an actual separator show, with the right insets.

    In more details: if you are using the storyboard, drag a UIView to the bottom of your Table View (in the tree view on the left) so it shows just below Table View Cell, at the same hierarchical level. This creates a tableFooterView. Of course this can be done programmatically as well.

    Then, in your UITableViewController's implementation:

    UIView *footerView = self.tableView.tableFooterView;
    CGRect footerFrame = footerView.frame;
    footerFrame.size.height = 0;
    [footerView setFrame:footerFrame];
    

    Let me know if that works for you! It might also work for the first separator if you use a tableHeaderView instead, I haven't tried it though.

提交回复
热议问题