Can I force a UITableView to hide the separator between empty cells?

This question already has an answer here:

  • Eliminate extra separators below UITableView [closed] 31 answers

  • You can achieve what you want by defining a footer for the tableview. See this answer for more details:Eliminate Extra separators below UITableView


    For iOS 7.* and iOS 6.1

    The easiest method is to set the tableFooterView property:

    - (void)viewDidLoad 
    {
        [super viewDidLoad];
    
        // This will remove extra separators from tableview
        self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    }
    

    For previous versions

    You could add this to your TableViewController (this will work for any number of sections):

    - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
         // This will create a "invisible" footer
         return 0.01f;
     }
    

    and if it is not enough , add the following code too :

    - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
    {        
        return [UIView new];
    
        // If you are not using ARC:
        // return [[UIView new] autorelease];
    }
    

    对于Swift:

    override func viewDidLoad() {
        super.viewDidLoad()
        tableView.tableFooterView = UIView()  // it's just 1 line, awesome!
    }
    
    链接地址: http://www.djcxy.com/p/44220.html

    上一篇: 在触摸UITextField外部时关闭键盘

    下一篇: 我可以强制UITableView隐藏空单元格之间的分隔符吗?