SamehDos
SamehDos

Reputation: 1203

Activate uitableview by touch inside

I have disabled my tableview by

[self.tableView setScrollEnabled:NO];

[self.tableView setAllowsSelection:NO];

I want to click anywhere in my table to reactivate the table . can I do that ?

Upvotes: 2

Views: 563

Answers (4)

Mat
Mat

Reputation: 7643

You could use a UITapGestureRecognizer as mentioned:

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(showTable:)];
[tapGesture setNumberOfTapsRequired:1];
[self.tableView addGestureRecognizer: tapGesture];
[tapGesture release];

and the action

-(void) showTable:(UITapGestureRecognizer *)recognizer {
    if (recognizer.state == UIGestureRecognizerStateEnded) {
        UIView *table=recognizer.view;
        if ([table isKindOfClass: [UITableView class]]) {
            UITableView *tab=(UITableView *)table;
            if (![tab isScrollEnabled]) {
                [tab setScrollEnabled:YES];
                [tab setAllowsSelection:YES];
            }
        }
    }
}

(Not tested) Hope this helps.

Upvotes: 3

eric.mitchell
eric.mitchell

Reputation: 8855

If your UITableView is full screen, then:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {   
    //make UITableView active here
}

If it isn't, you should do something like:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch* touch = [touches anyObject];
    if(CGRectContainsPoint(yourTableView.frame, touch)) {
        //make UITableView active here
    }
}

In order to do this, you have to make sure that self is the first responder, which you can do by including the

- (BOOL)canBecomeFirstResponder {
    return YES;
}

in your view controller and somewhere calling

[self becomeFirstResponder];

Upvotes: 1

ySgPjx
ySgPjx

Reputation: 10265

You could either use a UITapGestureRecognizer (pretty easy, there are tutorials everywhere) or a UIView subclass (put on top of the table view) that removes itself from the view hierarchy as soon as you touch it (in touchesBegan:withEvent: or touchesEnded:withEvent:).

Upvotes: 1

Leena
Leena

Reputation: 2676

you can use UITapGestureRecognizer.

Upvotes: 0

Related Questions