質問

私はGestureRecognizerの私UITableViewCellに問題がある、私はスワイプ左と右のジェスチャー、タップ&ホールド2秒のために持っているとテーブルビューのセルにジェスチャーをピンチ、スワイプ、右の次の章のために、前の章放置スワイプ、ピンチ別のビューコントローラにリダイレクトし、テーブルと呼ばれる単一のテーブルビューに実装されている.ALL(サブビュー)を表示するポップアップのために保持2秒。私の問題は、すべてのものは罰金を動作しますが、それはswipeGestureが機能していないにもピンチすることができるstucksテーブルビューでジェスチャーを使用していくつかの長い期間の後です。しかし、私は別のページに移動して戻ってきたとき、それは通常の作業を開始します。そしてそれはまた、いくつかの時間後にstucks。これを解決する方法私のコードはありますか?

- (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];

}
我々は左右スワイプとき、または

ともアクションも非常に遅いです。 私を助けてくださいます。

役に立ちましたか?

解決

You add a recognizer every time the routine tableView:cellForRowAtIndexPath: is called, and remove one after a gesture is processed. So after all recognizers (number of them equals number of cells) are removed, the gesture won't be recognized.

Perhaps you should not remove the recognizer in handling routine?

他のヒント

Your gesture recognizers apply to the whole table, yet you add them every time a cell is created!

Instead of adding the gesture recognizers to the whole table every time it creates a cell, try adding them somewhere else. Or if you mean to have the gestures in just cells, try using:

[cell addGestureRecognizer:recognizer];

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top