Search code examples
iosobjective-cuitableviewuiviewtouch-event

when touches outside the tableview.How to dismiss the tableView?


How to dismiss the tableview when we click on the view?i am using the touch began method.but its not working?

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"touches began");
UITouch *touch = [touches anyObject];   
if(touch.view!=myTableView){
   myTableview.hidden = YES;
}
}

how to disable the table when we click on view.i am having three tableviews?


Solution

  • Try this

    ViewDidLoad

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handelGesture:)];
            [self.view addGestureRecognizer:tap];
    

    ActionMethod

    - (void) handelGesture:(UITapGestureRecognizer*)sender
        {
            myTableview.hidden = YES;
        }
    

    Hope this helps.