Reputation: 47
Here's the scenario :
I have a UITableView, and a UITextView, added as subviews on a UIView. When the user touches on any of the row, I want 2 things - resignFirstResponder for the UITextView and I want a pop type UIView added for the particular row.
That is done.
But I want the same functionality of resignFirstResponder for the UITextView when the user touches on the region of the tableView where there are no rows.
How to do that, is there any method of tableView, which lets me handle the touches on the region where there are no rows?
Upvotes: 2
Views: 7877
Reputation: 577
What u ll have to do is, create a custom UITableView
. (subclassing UITableView
, by creating a new file)
Override the 'touchesBegan
' method of this custom tableView (which we can do because UITableView
is a subclass of a UIView
)
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//resignFirstResponder for the UITextView
//call didSelectRow of tableView again, by passing the touch to the super class
[super touchesBegan:touches withEvent:event];
}
What we are doing is that, we are overriding how the UITablView
catches the touch. We can do that in the touchesBegan
method, as UITableView
is a subclass of UIView
itself.
So we can override the touchesBegan
method, to catch the touch on the UITableView
, and then pass it further on to the super class of our custom tableView, which is UITableView
, so that its 'didSelectRow
' method gets called.
Upvotes: 2
Reputation: 6196
Haven't tested but I think you could add a touchevent to the tableview's backgroundView.
You can access the background view with tableView.backgroundView
Hope this helps
Upvotes: 0