Alienz
Alienz

Reputation: 118

Long press issues on uitableview cell when editing

Please see my code below. When I enter edit mode, I can't drag cells up and down because of the long press recognizer. If I remove the long press recognizer, everything works as it should.

Any help is appreciated.

    - (void)startEditingIndex
    {
        [self.navigationController setToolbarHidden:NO animated:YES];
        [self.tableView setEditing:YES animated:YES];
    }


    // Customize the appearance of table view cells.
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

        static NSString *CellIdentifier = @"Cell";

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
            cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
            cell.textLabel.numberOfLines = 0;
        }

        UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(startEditingIndex)];
        [cell addGestureRecognizer:longPress];
        [longPress release];


        NSString *cellText = @"Text";

        cell.textLabel.text = [[self.indexArry objectAtIndex:[[self.indexOrder objectAtIndex:indexPath.row] intValue]] objectForKey:cellText];

        return cell;
    }

Upvotes: 0

Views: 3136

Answers (1)

titaniumdecoy
titaniumdecoy

Reputation: 19251

Set your class as the delegate of longPress and implement the following delegate method:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
    return ![self.tableView isEditing];
}

Upvotes: 3

Related Questions