Click Ahead
Click Ahead

Reputation: 2852

Prevent UITableView from scrolling when I add a UIView with UIDatePicker on top of it

I'm trying to show a UIView with a UIDatePicker on top of a UITableView. The idea is that when a user selects a row the UIView (with a semitransparent background) containing a UIDatePicker subview slides up emulating a 'modal' view i.e. the user can interact with the UIDatePicker but nothing else.

Modal View

This works to a point, except when I scroll the UIDatePicker the UITableView scrolls too. I thought setting userInteractionEnabled=NO on my UITableView would work but it doesn't.

Anyone have any idea why ?

Upvotes: 1

Views: 434

Answers (2)

Click Ahead
Click Ahead

Reputation: 2852

Figured out the problem, the frame of the 'modal' UIView was wrong. It had the frame of the UITableView (height=480), when it should have been the frame of the UIWindow (height=568). This meant the scroll target was off.

Upvotes: 0

Logan
Logan

Reputation: 53132

Have you tried setting scrollable to NO?

tableView.scrollEnabled = NO;

After reviewing your question, I have a couple questions about what's going on.

If you are presenting the UIView over the tableView and then setting the UIView's userInteractionEnabled to NO, then the UIView will pass touches to the tableView. You would need to set userInteractionEnabled to YES if you want that view to block interaction with the tableView;

Upvotes: 1

Related Questions