Search code examples
xcodeuitableviewcss-selectorssubviews

UITableView becomes unresponsive


UITableViewCell becomes unresponsive this was a very different problem with a very different solution.

My tableView which is a subView in a UIViewController initially works fine and I can select individual rows in the table. However, I have created my own popup when a row is selected (the popup is a UIView) that appears towards the bottom of the screen. As this pops-up I also create a another UIView which covers the screen behind the popup and it makes the background go dim. The third thing that happens is that i create a UITapGestureRecogniser to keep track of the user's taps, and if they tap outside the UIView then the two UIViews and the TapGestureRecogniser are removed and call the deselectRowAtIndex... method.

However, it is at this point that I cannot use the tableView, as i want to be able to select a different string within the tableView and the popup to appear again (the popup will eventually contain links that will enable the user to move to different viewControllers).

I have tried to reload the data, remove the tableview and replace it, edit the didSelectRowAtIndex, remove the deselectRowAtIndex method, however nothing I tried seems to work and i can't find anything on stackoverflow as my question seems to be quite specific (although I apologise if there is something out there).

I'll add a few parts of my code in, however, I'm not sure where the problem is and I may not have copied the right part in.

The remove overhead is the selector method from the tapGesture

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{


    if(_popOverView == nil)
    {
    _popOverView = [[UIView alloc]initWithFrame:CGRectMake(20, 200, 280, 150)];

    _popOverView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"wood.jpeg"]];
    }
    if(_mask == nil)
    {
       _mask    = [[UIView alloc] initWithFrame:self.view.frame];
        [_mask setBackgroundColor:[UIColor colorWithWhite:0.0 alpha:0.78]];
    }

    if (_tapDetector == nil)
    {
        _tapDetector= [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(removeOverHead:)];
    }


    [self.view addSubview:_mask];
    [self.view addSubview:_popOverView];
    [self.view addGestureRecognizer:_tapDetector];


}



-(void) removeOverHead:(UITapGestureRecognizer*) sender
{

    CGPoint locationOfTap = [_tapDetector locationInView:self.view];


    if (locationOfTap.y < (200 + 150) && locationOfTap.y > 200 && locationOfTap.x > 20 && locationOfTap.x < (20 + 280) ) {


     NSLog(@"%f,%f",[_tapDetector locationInView:self.view].x,[_tapDetector locationInView:self.view].y);

    }

    else
    {

        [_mask removeFromSuperview];
        [_popOverView removeFromSuperview];
        [_tapDetector removeTarget:self action:@selector(removeOverHead:)];



        /*this idea doesn't work :(
         [self.tableView removeFromSuperview];
        [self.view addSubview:_tableView];*/



    }
}

I really hope the answer is in here and is very simple, and thank you in advance for taking the time to read this.


Solution

  • Solved it! Sorry for wasting your time. It was the wrong remove method for the gestureRecogniser. I replaced

    [_tapDetector removeTarget:self action:@selector(removeOverHead:)] 
    

    with

    [self.view removeGestureRecognizer:_tapDetector] 
    

    as the UIGestureRecogniser was lingering and obstructing the tableView!!