UIButton in a UITableView header ignores most touches

前端 未结 9 2341
盖世英雄少女心
盖世英雄少女心 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:21

    You should consider that this is not the intended sue of the headerView and that an implementation such as that might result in rejection from the AppStore as a result of a HIG violation. Given that the dimensions of a header are intended to be small, it is probably better to consider a restructuring of your view. Having said that, there is no easy way to do it short of hand detecting touch events and determining the geometry yourself, then executing a selector based on the geometry - in short, rolling your own button class.

    0 讨论(0)
  • 2020-12-28 19:24

    I completely disagree with Wisequark -- there's absolutely nothing wrong with putting a button in the tableHeaderView, and including one would not risk your app being rejected from the app store. The tableHeaderView is designed to be an arbitrary view containing whatever elements you choose.

    As far as your issue, it could be that you've got a view obscuring your button, or, it may simply be a bug that should be reported to Apple.

    0 讨论(0)
  • 2020-12-28 19:30

    I had a similar problem - a textfield and button inside a view set as the table header view which would not respond to touch events. setAutoResizing programmatically worked for me.

    My controller extends UITableViewController, and viewDidLoad looks like this:

    - (void)viewDidLoad
    {
        [super viewDidLoad];
    
        MYCustomWidget *headerView = [[[NSBundle mainBundle] 
                   loadNibNamed:@"MYCustomWidgetView" owner:self options:nil] 
                   objectAtIndex:0];
    
        [headerView setAutoresizingMask:UIViewAutoresizingNone];
    
        self.tableView.tableHeaderView = headerView;
    }
    

    ('MYCustomWidget' extends UIView, and 'MYCustomWidgetView' is a XIB file).

    0 讨论(0)
提交回复
热议问题