2010-12-09 75 views
0

嘿!我需要在uitableviewcell中添加計數,這樣當我觸發滑動功能時,計數應該在相應的單元格中遞增,同時點擊計數應該遞減..任何人都可以幫我解決這個問題..UITableViewCell中的自定義滑動功能不起作用

(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

如果你將你的問題中的代碼格式化爲代碼,它將會有所幫助......這是不可能的。 – SpaceDog 2010-12-31 05:44:34

回答

3

的UISwipeGestureRecognizer不添加到單元格。將它添加到UITableView。

我用TISwipeableTableView爲基礎,修改它在很大程度上能夠正常工作(他們做了他們自己的觸摸操控,這就造成了一個「奇怪的,unnative」的感覺)

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

這應該讓你開始。

0

[細胞addGestureRecognizer:識別]

+0

我已添加,但它不適用於此。 – 2010-12-10 09:19:06

相關問題