2010-12-09 3 views
0

Эй! Мне нужно добавить счет в ячейку uitableview таким образом, что когда я запускаю функцию салфетки, счет должен быть увеличен в соответствующей ячейке, а при постукивании счет должен быть уменьшен. Может ли кто-нибудь помочь мне в этом.Пользовательская функция салфетки в 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