UIButton in a UITableView header ignores most touches

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

提交回复
热议问题