TKutal TKutal - 1 year ago 55
Objective-C Question

UITableView becomes inactive when a view is shown

I have a

with some values in every cell. Next I have is a
that is shown when user taps on anyone of the cell. Now what I want to do is allow the user to select multiple cells and be able to scroll the
, but somehow the
becomes inactive whenever the
is shown. The
of the
is not disabled anywhere so that's not an issue. Here is the code that is used to show the
when user taps on a cell.

if (communicationView.hidden)
[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationCurveEaseOut animations:^{
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
[communicationView setFrame:CGRectMake(0, 0, 320, communicationView.frame.size.height)]; }
completion:^(BOOL finished) {
[self.contactsTblView setUserInteractionEnabled:YES];

Any help will be appreciated. Thank you.

Here is why I want to do this: The
that is presented when a cell is tapped contains two options 'Communicate' and 'Cancel', if user selected Communicate he is presented with another view to choose between Skype, Email etc. As per the new requirement of the client he want to allow sending emails to multiple people at a time and to do that I will have to allow selection of multiple cells.

Answer Source

Here is what you can do buddy :)

Issue : 1. When you add a view to a window then it will start accepting all the user interactions preventing the view below it to get any of such interactions. Hence when you load a view on top of the tableView and try to tap on the cell which is below this view will never receive any such touch :)

  1. UITableView becomes inactive when a view is shown :

Nope, It won't :) UITableView is still very much user interactive but it won't respond to any of your touch basically because it will never receive any touch :)

How can I test it ???

Simple set your CommunicationView's frame to CGRect(0,0,self.tableView.frame.size.width,100) and try to scroll the tableview by touching the tableview's frame which is not covered by CommunicationView it still scrolls :) Believe me I just tested the same :)

Now why is it not working in my case ??

The only possibility I can think of is that your CommunicationView might be covering the whole screen. Try setting the background colour to your communicationView and check is it covering the whole screen or not :)

But does that mean I can never interact with tableView if there is a view on top of it ??

Absolutely you can :)

Assume you want to allow the user to tap on the cell which is exactly below your CommunicationView :) How can you do it ???

Here is how :)

All you need is hitTest method of UIView :)

This is my didSelectRowAtIndexPath where am creating a view called testView and adding it on to self.view.window at frame (0,0,width,200)

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    let testView : MyView = NSBundle.mainBundle().loadNibNamed("MyView", owner: nil, options: nil)[0] as! MyView
    testView.frame = CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 200)
    testView.backgroundColor = UIColor.redColor()
    testView.belowTableView = self.tableView

Now my testView covers few of the cell but I want to tap them as well :)

Here is what I did. Create a subclass of UIView lets call MyView :)

class MyView : UIView {
    var belowTableView : UITableView?

    override func hitTest(point: CGPoint, withEvent event: UIEvent?) -> UIView? {
        let hitView = super.hitTest(point, withEvent: event)
        return self.belowTableView

This will be set as my testView class :)

What the hell are you doing ??? I am overriding the hitTest method which is responsible for returning the view which is tapped :) So what am doing here is am capturing the touch on my testView rather then returning my self I return the tableView below it :)

So my iOS will believe that user tapped/touched the tableView and not the testView which is on top :)

But how will I tap on buttons ?? Simple modify the hitTest method :) Check if touch point is inside the buttons frame or not :) If it is inside button simply return hitView I calculated in above code else return self.belowTableView :)

Simple Isn't it :) Lemme know if you still have doubts :)