UIButton in a UITableView header ignores most touches

前端 未结 9 2493
盖世英雄少女心
盖世英雄少女心 2020-12-28 18:58

I\'ve got a button that I\'m adding as a subview of a table view\'s tableHeaderView. The button appears fine, and tap-and-holding on it works intermittently - for the most p

9条回答
  •  無奈伤痛
    2020-12-28 19:07

    Strangely enough, but the table header view is apparently resized incorrectly. I use auto layout, so autoresizing mask was not an option for me. After inspecting my view hierarchy:

    and noticed that my custom header view had incorrect height, so only less then half of it was tappable (see highlighted view):

    Manual updating of its height fixed the problem:

    - (void)viewDidLayoutSubviews {
        CGRect frame = self.tableView.tableHeaderView.frame;
        frame.size.height = 116.0;
        self.tableView.tableHeaderView.frame = frame;
    }
    

    Also, the table view header height can become invalid after the orientation is changed. This problem also can be fixed with the provided solution.

提交回复
热议问题