2010-12-09 46 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

相关问题