5

kullanıyorum jest tanıyıcılar: viewDidLoad yılındaBir kullanıcının bir UITableViewCell'i 2 saniye boyunca basılıp basmadığını nasıl belirleyebilirim?

başlatma:

UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)]; 
[self.view addGestureRecognizer:longPressRecognizer]; 

Bu longPress neye benzediği:

- (void)longPress:(UILongPressGestureRecognizer*)gestureRecognizer { 
if (gestureRecognizer.minimumPressDuration == 2.0) { 
    NSLog(@"Pressed for 2 seconds!"); 
} 
} 

nasıl bu işe kravat olabilir?

- (void)tableView:(UITableView *)tblView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

Nasıl didSelectRowAtIndexPath gestureRecognizer.minimumPressDuration bir başvuru alacak?

Temelde ne elde etmek çalışıyorum geçerli:

**If a user clicks on a cell, check to see if the press is 2 seconds.** 

cevap

3

deneyin

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { 
    [cell addGestureRecognizer:longPressRecognizer]; 
}
2

yerine tableview, tableviewcell için gesturerecognizer eklemeyi deneyebilirsiniz. UITableViewCells, UIView'den hareketle jest tanıyıcılarını kabul edebiliyor. willDisplayCell: forRowAtIndexPath: gibi pek yöntemi: tableView sağlayarak yerine UITableView UITableViewCell eklemeden

+0

kodda gösterebilir misin? –

+1

Steve sadece bunu yapmış görünüyor. –

1

tableviewcell etiketine bir indexpath.row eklemek

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

static NSString *CellIdentifier = @"Cell"; 

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
} 
UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(rowButtonAction:)]; 
[cell setTag:indexPath.row]; 
[cell addGestureRecognizer:longPressRecognizer]; 
[longPressRecognizer release]; 

// Configure the cell... 
Group *gp = [_currentItemArray objectAtIndex:indexPath.row]; 
cell.textLabel.text = gp.name; 


return cell; 

ve daha sonra bu etikete [[gestureRecognizer view] etiketi] kullanarak uzun basınca erişin. myModalViewController.previousObject = [_currentItemArray objectAtIndex: [[sender view] tag]] ile bölümü;

-(IBAction)rowButtonAction:(UILongPressGestureRecognizer *)sender{ 
if (sender.state == UIGestureRecognizerStateEnded) { 
    GroupsAdd_EditViewController *myModalViewController = [[[GroupsAdd_EditViewController alloc] initWithNibName:@"GroupsAdd_EditViewController" bundle:nil] autorelease]; 
    myModalViewController.titleText = @"Edit Group"; 
    myModalViewController.context = self.context; 
    myModalViewController.previousObject = [_currentItemArray objectAtIndex:[[sender view] tag]]; 
    [self.navigationController presentModalViewController:myModalViewController animated:YES]; 
} 

}

İlgili konular