Burnie777 Burnie777 - 3 years ago 58
iOS Question

Pushing a button in a Scrollview without UserInteraction on

I am using an UITableView with headers and footers, the whole TableView has horizontal UIScrollViews inside. I use it as a lock titles function, like in Excel.

The UserInteraction is disabled on the UIScrollView in the UITableview Header and UITableView Footer and only scrolls when the body scrolls.

In my header I now have a button which is situated in the UIScrollViews ContentView and I need to be able to interact with it, which does not... Has anyone come across this in the past?

Much of the unneeded code has been omitted...

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
UITableViewHeaderFooterView *viewHeader;

UIButton *flow;

viewHeader = [[UITableViewHeaderFooterView alloc] initWithFrame:CGRectMake(0, 1, self.tableview.frame.size.width, 48)];

UIView *thisContentView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, contentWidth, 48)];

flow = [[UIButton alloc] initWithFrame:CGRectMake( flowRate.frame.origin.x + flowRate.frame.size.width + 5, 14, colWidth1, 20)];
[flow.imageView setImage:[UIImage imageNamed:@"ic_flow"]];
flow.imageView.contentMode = UIViewContentModeScaleAspectFit;
[flow setContentMode:UIViewContentModeScaleAspectFit];
[UniversalMethods tintImageviewInButton:flow withColor:BRIGHT_BLUE];

[flow addTarget:self action:@selector(showSortingAlert:) forControlEvents:UIControlEventTouchUpInside];

[thisContentView addSubview:flow];

[thisScrollview addSubview:thisContentView];
thisScrollview.contentSize = thisContentView.frame.size;
thisScrollview.tag = scrollTag;
[thisScrollview setUserInteractionEnabled:false];

[viewHeader addSubview:thisScrollview];

return viewHeader;

Answer Source

When userInteraction is disabled on a view, it also prevents touch events from being passed down to its subviews. You'll need to enable userInteraction on the scrollview in order to tap the button. You can set isScrollEnabled to false in order to prevent the scrollview from scrolling.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download