2010-12-09 10 views
0

Hey! Ich muss die Zählung in der uitableviewcell in einer solchen Weise hinzufügen, dass, wenn ich die Swipe-Funktion auslöst, die Zählung in der entsprechenden Zelle inkrementiert werden sollte und während das Tippen der Zählung verringert werden sollte. Kann mir jemand dabei helfen ..Benutzerdefinierte Swipe-Funktion in UITableViewCell funktioniert nicht

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
UITableViewCell *cell = nil; 
NSString *CellIdentifier = @"sample"; 
     if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 

} 
UISwipeGestureRecognizer *recognizer; 

recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTapFrom:)]; 
[self addGestureRecognizer:recognizer]; 
    self.tapRecognizer = (UITapGestureRecognizer *)recognizer; 
    recognizer.delegate = self; 
[recognizer release]; 


recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)]; 

[self addGestureRecognizer:recognizer]; 
[recognizer release]; 
UILabel *cookieLabel = [[UILabel alloc] initWithFrame:CGRectMake(5,5, 120,30)]; 
cookieLabel.text = @"hello"; 
cookieLabel.font = [UIFont systemFontOfSize:15.0f]; 
cookieLabel.textColor = [UIColor blackColor]; 
cookieLabel.backgroundColor = [UIColor redColor]; 
[cell.contentView addSubview:cookieLabel]; 
[cookieLabel release]; 
cell.selectionStyle = UITableViewCellSelectionStyleGray; 

costLabel = [[UILabel alloc] initWithFrame:CGRectMake(200, 5, 230, 30)]; 
//costLabel.text = handleSwipeFrom:; 
costLabel.font = [UIFont systemFontOfSize:15.0f]; 
costLabel.textColor = [UIColor blackColor]; 
costLabel.backgroundColor = [UIColor greenColor]; 
[cell.contentView addSubview:costLabel]; 
[costLabel release]; 
[self setUserInteractionEnabled:YES]; 

return cell; 
} 
+0

wird es helfen, wenn Sie den Code in Ihrer Frage als Code formatieren ... es ist unmöglich, dies zu lesen. – SpaceDog

Antwort

3

Sie das UISwipeGestureRecognizer an die Zelle nicht hinzuzufügen. Fügen Sie es dem UITableView hinzu.

I verwendet TISwipeableTableView als Basis und modifiziert es schwer richtig zu arbeiten (sie ihre eigene Note Handhabung haben, die in einem „weird, unnative“ Gefühl führte)

- (void)didSwipe:(UIGestureRecognizer *)gestureRecognizer { 
    if ([MRUserDefaults sharedMRUserDefaults].isSwipeMenuEnabled) { 
    if (gestureRecognizer.state == UIGestureRecognizerStateEnded) { 
     CGPoint swipeLocation = [gestureRecognizer locationInView:self]; 
     NSIndexPath *swipedIndexPath = [self indexPathForRowAtPoint:swipeLocation]; 
     TISwipeableTableViewCell* swipedCell = (TISwipeableTableViewCell *)[self cellForRowAtIndexPath:swipedIndexPath]; 

     if ([swipedCell isKindOfClass:[TISwipeableTableViewCell class]]) { 
     if (![swipedIndexPath isEqual:indexOfVisibleBackView]) { 
      [self hideVisibleBackView:YES]; 
      [swipedCell revealBackView]; 
      [self setIndexOfVisibleBackView:swipedIndexPath]; 

      if (swipeDelegate && [swipeDelegate respondsToSelector:@selector(tableView:didSwipeCellAtIndexPath:)]){ 
      [swipeDelegate tableView:self didSwipeCellAtIndexPath:[self indexPathForRowAtPoint:swipeLocation]]; 
      }   
     } 
     } 
    } 
    } 
} 

- (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style { 
    if ((self = [super initWithFrame:frame style:style])) { 
    if ([MRUserDefaults sharedMRUserDefaults].isSwipeMenuEnabled) { 
     UIGestureRecognizer *swipeGesture = [[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(didSwipe:)] autorelease]; 
     [self addGestureRecognizer:swipeGesture]; 
    } 
    } 
    return self; 
} 

Dies sollte Ihnen den Einstieg.

0

[Zelle addGestureRecognizer: Erkenner]

+0

Ich habe hinzugefügt, aber es funktioniert auch nicht für .. –

Verwandte Themen