2012-03-16 13 views
7

Masamın başlık görünümü bölümünde bu var:UITapGestureRecognizer'da @selector argüman nasıl iletilir?

UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(sectionHeaderTapped:)]; 

Ben bu yüzden aday var hangi bölümü tanıyabilir yöntemde sectionHeaderTapped bölüm numarasını geçmek istiyorum.

-(void)sectionHeaderTapped:(NSInteger)sectionValue { 
    NSLog(@"the section header is tapped ");  
} 

Bunu nasıl elde edebilirsiniz:

Benim yöntemim uygulama aşağıdaki gibi görünüyor?

cevap

15

yöntemi:

- (void)sectionHeaderTapped:(UITapGestureRecognizer *)sender; 
- (void)sectionHeaderTapped; 

Sen musluğun koordinatlarını kullanarak aday hücreyi bulmalıyız.

-(void)sectionHeaderTapped:(UITapGestureRecognizer *)gestureRecognizer 
{ 
    CGPoint tapLocation = [gestureRecognizer locationInView:self.tableView]; 
    NSIndexPath *tapIndexPath = [self.tableView indexPathForRowAtPoint:tapLocation]; 
    UITableViewCell* tappedCell = [self.tableView cellForRowAtIndexPath:tapIndexPath]; 
} 

Muhtemelen bölüm üstbilgisini bu yöntemi kullanarak alabilirsiniz. Ancak, her bölüm başlığına farklı bir jest tanıyıcı eklemek daha kolay olabilir.

- (UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section 
{ 
    // ... 
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(sectionHeaderTapped:)]; 
    [headerView addGestureRecognizer:tapGesture]; 
    return headerView; 
} 

Sonra

-(void)sectionHeaderTapped:(UITapGestureRecognizer *)gestureRecognizer 
{ 
    UIView *headerView = gestureRecognizer.view; 
    // ... 
} 
+0

evet ben her bölüm değil, en iyi yolu farklı jestler kullanmış ancak yolu daha kolay ... Teşekkürler –

+0

Vali .... teşekkürler cevap .. –

0

Bir alternatif: tableHeaderView'a UIButton ekleyebilir ve düğmeyi tıklayabilirsiniz. Aşağıdaki imzaların birinde olmalıdır sectionHeaderTapped

İlgili konular