2011-10-12 16 views
27

Şu anda UIImageView içeren ve UIImageView üzerinde UITImageView eklentisi eklemeye çalışan özel bir UITableViewCell var. İşte kodun snippet'i.UITImageGenişRecognizer UIImageView içinde UITablevlewCell denir almayan

//within cellForRowAtIndexPath (where customer table cell with imageview is created and reused) 
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleImageTap:)]; 
tap.cancelsTouchesInView = YES; 
tap.numberOfTapsRequired = 1; 
tap.delegate = self; 
[imageView addGestureRecognizer:tap]; 
[tap release]; 

// handle method 
- (void) handleImageTap:(UIGestureRecognizer *)gestureRecognizer { 
    RKLogDebug(@"imaged tab"); 
} 

Ben de hücre ve UIImageView Superview ama hala hiçbir şans, herhangi ipuçları üzerinde userInteractionEnabled seti ettik?

DÜZENLEME:

Ben de cell.selectionStyle = UITableViewCellSelectionStyleNone tarafından hücrenin seçimi kaldırmak ettik; Bu sorun,

+0

İlk olarak, neden görüntü görünümü yerine UIButton kullanmıyorsunuz? İkinci olarak, gerçek görüntü görünümü için kullanıcı etkileşimini etkinleştirdiniz mi? – Rog

+0

@Rog 'cus UIImageView'ın UIViewContentModeScaleAspectFit işlevini kullanmak istiyorum, UIButton aynı işlevselliğe sahip mi? – Herman

+0

Ayrıca, UIControl'ü scrollview modunda kullanırken, dokunmaya başladığınızda kaydırma işlemini engeller ... – JakubKnejzlik

cevap

98

UIImageView'ün kullanıcı etkileşimi varsayılan olarak devre dışı bırakılmış olabilir. Dokunmalara yanıt vermesi için bunu açıkça etkinleştirmeniz gerekir. Benim durumumda

imageView.userInteractionEnabled = YES; 
+2

Bunu zaten yaptım ama hala şansım yok – Herman

+0

benim için çalıştı ... teşekkürler! – samfisher

+1

Belki de üzerinde UIView var? –

0

görünüyor gibi:

- (UITableViewCell *)tableView:(UITableView *)tableView 
     cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSString *cellIdentifier = CELL_ROUTE_IDENTIFIER; 
    RouteTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; 

    if (cell == nil) { 
     cell = [[RouteTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
             reuseIdentifier:cellIdentifier]; 
    } 

    if ([self.routes count] > 0) { 
     Route *route = [self.routes objectAtIndex:indexPath.row]; 

     UITapGestureRecognizer *singleTapOwner = [[UITapGestureRecognizer alloc] initWithTarget:self 
                        action:@selector(imageOwnerTapped:)]; 
     singleTapOwner.numberOfTapsRequired = 1; 
     singleTapOwner.cancelsTouchesInView = YES; 
     [cell.ownerImageView setUserInteractionEnabled:YES]; 
     [cell.ownerImageView addGestureRecognizer:singleTapOwner]; 
    } else { 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
    } 
    return cell; 
} 

Ve seçicinin:

- (void)imageOwnerTapped:(UISwipeGestureRecognizer *)gesture { 
    CGPoint location = [gesture locationInView:self.tableView]; 
    NSIndexPath *tapedIndexPath = [self.tableView indexPathForRowAtPoint:location]; 
    UITableViewCell *tapedCell = [self.tableView cellForRowAtIndexPath:tapedIndexPath]; 

    NSIndexPath *indexPath = [self.tableView indexPathForCell:tapedCell]; 
    NSUInteger index = [indexPath row]; 

    Route *route = [self.routes objectAtIndex:index]; 
} 
2

Swift 3

Bu benim için çalıştı:

self.isUserInteractionEnabled = true