5

내가 사용하고 제스처 인식기 : viewDidLoad에서사용자가 UITableViewCell을 2 초 동안 눌렀는지 어떻게 확인할 수 있습니까?

초기화 :

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

longPress는 모습입니다 :

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

어떻게이로 묶을 수있다?

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

어떻게 didSelectRowAtIndexPath는 gestureRecognizer.minimumPressDuration에 대한 참조를받을 수 있습니까?

기본적으로 내가 무엇을 달성하기 위해 노력하고있어입니다 :

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

답변

3

시도

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

당신은 대신있는 tableview의, tableviewcell에 gesturerecognizer를 추가하는 시도 할 수 있습니다. UITableViewCells는 UIView에서 파생되므로 제스처 인식기를 사용할 수 있습니다. willDisplayCell : forRowAtIndexPath : 같은 방법 다음있는 tableView를 제공하여 대신 jQuery과의있는 UITableViewCell에 추가

+0

당신은 코드에서 저를 보여줄 수 있습니까? –

+1

스티브가 그렇게 한 것 같습니다. –

1

이 tableviewcell의 태그에 a를 indexpath.row를 추가

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

}

그리고 [[gestureRecognizer보기] 태그]를 사용하여 longPress에서 해당 태그에 액세스하십시오. myModalViewController.previousObject = [_currentItemArray objectAtIndex : [[보낸 사람보기] 태그]];

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

은}

관련 문제