سؤال

ولدي مشكلة مع GestureRecognizer بلدي في UITableViewCell، ولدي اليسار ومرر لفتة الصحيحة، الحنفية عقد لمدة 2 ثانية وقرصة لفتة في الخلية tableview، انتقاد اليمين للفصل القادم، انتقاد اليسار للفصل السابق، قرصة ل إعادة توجيه إلى رؤية وحدة تحكم أخرى، وعقد 2 ثانية لالمنبثقة لتظهر (أ subview) تنفذ. جميع في tableview واحد يسمى الجدول. مشكلتي هي كل شيء يعمل بشكل جيد، ولكن بعد بعض فترة طويلة من استخدام الإيماءات في tableview ذلك stucks وswipeGesture يمكن قرصة أيضا لا يعمل. ولكن عندما أذهب إلى صفحة أخرى وعاد ذلك بدء العمل العادي. و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];

}

ووأيضا عندما كنا مرر لليسار أو اليمين العمل بطيء جدا أيضا. الرجاء مساعدتي.

هل كانت مفيدة؟

المحلول

ويمكنك إضافة التعرف في كل مرة tableView الروتينية: cellForRowAtIndexPath: يسمى، وإزالة واحدة بعد معالجتها لفتة. بعد كل ذلك التعرف (عدد منهم يساوي عدد الخلايا) يتم إزالتها، لن يتم التعرف على لفتة.

وربما كنت لا ينبغي إزالة التعرف في التعامل مع الروتين؟

نصائح أخرى

وتنطبق التعرف فتة الخاص بك إلى الجدول بأكمله، بعد إضافتها في كل مرة يتم إنشاء خلية!

وبدلا من إضافة التعرف فتة إلى الجدول بأكمله في كل مرة يخلق خلية، حاول إضافة لهم في مكان آخر. أو إذا كنت تقصد أن يكون لفتات في الخلايا عادلة، حاول استخدام:

[خلية addGestureRecognizer: التعرف]؛

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top