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
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.
I had the same problem. In my case I had a container view instantiated in IB (that was applied as the table view header in code), with a UIImageView occupying the entire frame of that container. The misbehaving button resided in the image view.
Turns out I needed to have sizing struts in IB set as follows...
Container View: exterior anchors all on, interior resizing - all off
Sub Image View: all struts on (interior and exterior)
I had several different table views, all using header views. Some would respond to touch events correctly, some were flaky. This solved my problem
Don't forget to set the footer height in:
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
I have the same problem UIButtons
actions not working in UITableView's
header view. First i tried setAutoresizingMask
to .None
which not works then after reading the answers of @Davyd and @Alexey i realise that i did not set the height of headers view then i set it like:-
self.tablevwMain.tableHeaderView?.frame = CGRect(x: 0, y: 0, width: width_view, height: your_height)
And all UIButton's
inside UITableView's
header view works correctly.
tableHeaderView has 0 height while it is processing draw in UITableView
use this UIView subclass to set the strong constant height and ignore UITableView processing
#import <UIKit/UIKit.h>
@interface CustomHeaderCell : UIView
@end
//-----
@import "CustomHeaderCell.h"
@implementation CustomHeaderCell
-(void)setFrame:(CGRect)frame {
frame.size.height = 43; // !!! constant height
[super setFrame:frame];
}
@end
My situation was similar to Danny Hall's (the table header view was a UIImageView, and there was a UIButton which was a subview of the UIImageView). In my case, the problem appears to have been caused by the button being a subview of the image view. What worked for me was creating a UIView "containing" view, such that both the image view as well as the button were subviews of the "containing" view. strange.