Question

J'ai un problème avec mon GestureRecognizer dans UITableViewCell, j'ai Gesture swipe gauche et à droite, appuyez sur attente pendant 2 secondes et une pincée Gesture dans la cellule tableview, Swipe droite pour le chapitre suivant, mouvement vers la gauche pour le chapitre précédent, pincez pour rediriger vers une autre vue-contrôleur, et maintenir 2 secondes pour un pop-up pour montrer (un sous-vue) .Toutes sont mises en œuvre en une seule table appelée tableview. Mon problème est tout fonctionne très bien, mais après une certaine longue période d'utilisation Gesture dans le tableview il stucks le swipeGesture peut être pincée aussi ne fonctionne pas. mais quand je vais à une autre page et je suis revenu, il commence à travailler normal. et il stucks après un certain temps aussi. Comment résoudre ce mon code est?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

   static NSString *CellIdentifier = @"Cell";

    readCell *cell = (readCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {

    UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)];
    swipeGesture.direction = UISwipeGestureRecognizerDirectionRight; // or whatever
    [table addGestureRecognizer:swipeGesture];
    [swipeGesture release];

    UILongPressGestureRecognizer *lpgr = [[UILongPressGestureRecognizer alloc] 
                                          initWithTarget:self action:@selector(handleLongPress:)];
    lpgr.minimumPressDuration = 1.0; //seconds
    lpgr.delegate = self;
    [table addGestureRecognizer:lpgr];
    [lpgr release];

    UISwipeGestureRecognizer *swipeGestureleft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGestureleft:)];
    swipeGestureleft.direction = UISwipeGestureRecognizerDirectionLeft; // or whatever
    [table addGestureRecognizer:swipeGestureleft];
    [swipeGestureleft release];

    UIPinchGestureRecognizer *longPressRecognizer = 
    [[UIPinchGestureRecognizer alloc]
     initWithTarget:self 
     action:@selector(longPressDetected:)];
    [self.view addGestureRecognizer:longPressRecognizer];
    [longPressRecognizer release];

-(void)handleLongPress:(UILongPressGestureRecognizer *)gestureRecognizer
{
    CGPoint p = [gestureRecognizer locationInView:table];

    NSIndexPath *indexPath = [table indexPathForRowAtPoint:p];
    if (indexPath == nil)
        NSLog(@"long press on table view but not on a row");
    else

        // localStringValueverseno= [tableView cellForRowAtIndexPath:indexPath];
        localStringValueverseno = [(UILabel *)[[table cellForRowAtIndexPath:indexPath]
                                               viewWithTag:1] text];
    localStringValue = [table cellForRowAtIndexPath:indexPath].textLabel.text; 
    _lblmainnotegns.text = localStringValueverseno;
    // localStringValueverseno= [tableView cellForRowAtIndexPath:indexPath].cell.table.chapterAndVerse.text; 
    delegate.selectedIndex=[NSString stringWithFormat:@"%d",indexPath.row+1];
    [userInfo setObject:[delegate.allSelectedVerseEnglish objectAtIndex:indexPath.row] forKey:@"text"];
    [userInfo setObject:delegate.selectedBook forKey:@"book"];
    [userInfo setObject:delegate.selectedChapter forKey:@"chapter"];
    [userInfo setObject:[NSString stringWithFormat:@"%d",indexPath.row + 1] forKey:@"verse"];

    UIView *noteView = (UIView *)[self.view viewWithTag:101]; 
    //ViewWithTag Number should be same as used while allocating
    [noteView removeFromSuperview];
    //For removing View
    UIView *acntView = (UIView *)[self.view viewWithTag:100]; 
    //ViewWithTag Number should be same as used while allocating
    [acntView removeFromSuperview];
    // now you can use cell.textLabel.text
    UIView *noteViewsync = (UIView *)[self.view viewWithTag:105]; 
    //ViewWithTag Number should be same as used while allocating
    [noteViewsync removeFromSuperview];


    if ([notes objectForKey:[NSString stringWithFormat:@"%@ %@:%@",delegate.selectedBook,delegate.selectedChapter,delegate.selectedIndex]] == nil) {
        [notetickimage setHidden:YES];
        [self.view addSubview:MainPopupView];
    }
    if (gestureRecognizer.state==UIGestureRecognizerStateBegan ) {
        self.table.scrollEnabled = NO;
        [table removeGestureRecognizer:gestureRecognizer];
    }
    else if(gestureRecognizer.state==UIGestureRecognizerStateEnded) {
        self.table.scrollEnabled = YES;
        [table removeGestureRecognizer:gestureRecognizer];
    }



        NSLog(@"long press on table view at row %d", indexPath.row);
}
-(void) handleSwipeGesture:(UISwipeGestureRecognizer*)recognizer {


     if(![delegate.selectedChapter isEqualToString:[NSString stringWithFormat:@"%d",[DbHandler mNumberOfChaptersInBook:delegate.selectedBook]]]) {
         [UIView beginAnimations:nil context:nil];
         [UIView setAnimationDuration:0.4];
         [UIView setAnimationDelay:0.0];
         [UIView setAnimationBeginsFromCurrentState:YES];
         [UIView setAnimationDidStopSelector:@selector(animCompleteHandler:finished:context:)];
         [UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
         [UIView commitAnimations];

        // if the currentChapter is the last then do nothing
         delegate.selectedChapter = [NSString stringWithFormat:@"%d",[delegate.selectedChapter intValue] + 1];
         [delegate reloadVerses];
         [self resetReadViewToVerse:1];
         [table removeGestureRecognizer:recognizer];
    }
    if (recognizer.state==UIGestureRecognizerStateBegan ) {
        self.table.scrollEnabled = NO;
        [table removeGestureRecognizer:recognizer];
    }
    else if(recognizer.state==UIGestureRecognizerStateEnded) {
        self.table.scrollEnabled = YES;
        [table removeGestureRecognizer:recognizer];
    }


    return;



}
-(void) handleSwipeGestureleft:(UISwipeGestureRecognizer*)recognizer {

    if(![delegate.selectedChapter isEqualToString:@"1"])
    {
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:0.4];
        [UIView setAnimationDelay:0.0];
        [UIView setAnimationBeginsFromCurrentState:YES];
        [UIView setAnimationDidStopSelector:@selector(animCompleteHandler:finished:context:)];
        [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
        [UIView commitAnimations];
        delegate.selectedChapter = [NSString stringWithFormat:@"%d",[delegate.selectedChapter intValue] - 1];
        [delegate reloadVerses];
        [self resetReadViewToVerse:1]; 
        [table removeGestureRecognizer:recognizer];
    }
    if (recognizer.state==UIGestureRecognizerStateBegan ) {
        self.table.scrollEnabled = NO;
        [table removeGestureRecognizer:recognizer];
    }
    else if(recognizer.state==UIGestureRecognizerStateEnded) {
        self.table.scrollEnabled = YES;
        [table removeGestureRecognizer:recognizer];
    }

    return;


}
-(void) longPressDetected:(UIPinchGestureRecognizer*)recognizer {


    self.table.scrollEnabled = NO;
    SearchViewController *aSecondViewController = [[SearchViewController alloc] initWithNibName:@"SearchViewController" bundle:nil];
    aSecondViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    [self presentModalViewController:aSecondViewController animated:YES];

    /*[self.navigationController pushViewController:aSecondViewController animated:YES];*/

    [aSecondViewController release];
    [UIView commitAnimations];
    [table removeGestureRecognizer:recognizer];

    UIView *noteView = (UIView *)[self.view viewWithTag:101]; 
    //ViewWithTag Number should be same as used while allocating
    [noteView removeFromSuperview];
    UIView *setngView = (UIView *)[self.view viewWithTag:102]; 
    //ViewWithTag Number should be same as used while allocating
    [setngView removeFromSuperview];
    UIView *acntView = (UIView *)[self.view viewWithTag:100]; 
    //ViewWithTag Number should be same as used while allocating
    [acntView removeFromSuperview];
    UIView *popView = (UIView *)[self.view viewWithTag:106]; 
    //ViewWithTag Number should be same as used while allocating
    [popView removeFromSuperview];

}

et aussi quand nous Balayez vers la gauche ou à droite l'action est très lent aussi. S'il vous plaît aidez-moi.

Était-ce utile?

La solution

Vous ajoutez un module de reconnaissance chaque fois que la routine tableView: cellForRowAtIndexPath: est appelé, et enlever l'un après un geste est traité. Ainsi, après tous (nombre d'reconnaisseurs leur est égal nombre de cellules) sont retirées, le geste ne sera pas reconnu.

Peut-être que vous ne devriez pas enlever la routine dans le traitement de reconnaissance?

Autres conseils

Votre geste de reconnaissance s'appliquent à toute la table, mais vous les ajoutez à chaque fois qu'une cellule est créée!

Au lieu d'ajouter le geste à la table de reconnaissance tout à chaque fois qu'il crée une cellule, essayez de les ajouter quelque part ailleurs. Ou si vous voulez dire d'avoir les gestes dans les cellules seulement, essayez d'utiliser:

[cellule addGestureRecognizer: reconnaisseur];

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top