2017-07-26 1 views
0

Je travaille sur une application tvOS dans laquelle une cellule de vue de table personnalisée est utilisée, tandis que l'affichage de données à l'aide d'étiquettes fonctionne parfaitement mais la sélection de bouton ne fonctionne pas. Y at-il un moyen de faire la sélection de bouton à l'intérieur de la cellule de vue de table personnalisée fonctionne dans la vue de table tvOS?Impossible de sélectionner le bouton dans la cellule de vue de table personnalisée dans tvOS

extrait de code:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
      { 
       MsgDetailsTableViewCell *cell; 
       static NSString *simpleTableIdentifier = @"Cell"; 
      cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 
       if (cell == nil) { 
        cell = [[MsgDetailsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; 
       } 

      NSDictionary*dataDict = [self.qArray objectAtIndex:indexPath.row]; 
      NSString *followCountText = [NSString stringWithFormat:@"%@ Following",[[dataDict objectForKey:@"followCount"] stringValue]]; 
       if([[dataDict objectForKey:@"followCount"] integerValue]!=0) 
       { 
        [cell.statusListBtn addTarget:self action:@selector(openLikedList:) forControlEvents:UIControlEventPrimaryActionTriggered]; 
        cell.statusListBtn.tag=111; 
        cell.followCountLbl.textColor = [UIColor colorWithRed:0/255.0 green:95/255.0 blue:167/255.0 alpha:1.0]; 
       } 
       else 
       { 
        [cell.statusListBtn removeTarget:self action:@selector(openLikedList:) forControlEvents:UIControlEventPrimaryActionTriggered]; 
        cell.statusListBtn.tag=111; 
        cell.followCountLbl.textColor = [UIColor grayColor]; 
       } 

       cell.followCountLbl.text=followCountText; 
      return cell; 
     } 

Dans le code ci-dessus Sélection de statusListBtn ne fonctionne pas.

+0

s'il vous plaît partager le code de méthode 'cellForRowAt' – Indrajeet

+0

question éditée @Indrajeet –

Répondre

0

Voulez-vous dire que seulement lorsque dataDict objectForKey:@"followCount"] integerValue]!=0 le bouton peut effectuer le sélecteur si c'est le cas. vous pouvez essayer cette

   MsgDetailsTableViewCell *cell; 
       static NSString *simpleTableIdentifier = @"Cell"; 
      cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; 
       if (cell == nil) { 
        cell = [[MsgDetailsTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier]; 
        [cell.statusListBtn addTarget:self action:@selector(openLikedList:) forControlEvents:UIControlEventPrimaryActionTriggered]; 
        cell.statusListBtn.tag=111; 
       } 

      NSDictionary*dataDict = [self.qArray objectAtIndex:indexPath.row]; 
      NSString *followCountText = [NSString stringWithFormat:@"%@ Following",[[dataDict objectForKey:@"followCount"] stringValue]]; 
       if([[dataDict objectForKey:@"followCount"] integerValue]!=0) 
       { 
        cell.statusListBtn.userInteractionEnabled = YES; 
        cell.followCountLbl.textColor = [UIColor colorWithRed:0/255.0 green:95/255.0 blue:167/255.0 alpha:1.0]; 
       } 
       else 
       { 
        cell.statusListBtn.userInteractionEnabled = NO; 
        cell.followCountLbl.textColor = [UIColor grayColor]; 
       } 

       cell.followCountLbl.text=followCountText; 
      return cell; 

Si vous voulez différents cas de bouton, vous pouvez changer UIControlEventPrimaryActionTriggered comme UIControlEventTouchUpInside