2016-08-02 1 views
0

Comment gérer didSelectRowAtIndexPath de sorte qu'il fonctionne sur les trois cellules différentes pour chaque cellule dedans?J'ai une tableview avec plusieurs cellules dedans et dans chaque cellule ayant tableview, collectionview, tableview, comme ça

Preview

Flow of my code

- (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
 
{ 
 
    if([[dataArray[indexPath.row] valueForKey:@"type"] isEqual:@"Traffic" ]) 
 
     { 
 
      if(!TrafficCell) 
 
      { 
 
       TrafficCell = [tableView dequeueReusableCellWithIdentifier:@"CollectionVIewTableViewCell" forIndexPath:indexPath]; 
 
       NSDictionary *dict=dataArray[indexPath.row]; 
 
       TrafficCell.Traffic = [dict valueForKey:@"detail"]; 
 
       [TrafficCell.collectionView reloadData]; 
 
       return TrafficCell; 
 
      } 
 
      return TrafficCell; 
 
     } 
 
    else if([[dataArray[indexPath.row] valueForKey:@"type"] isEqual:@"News"]) 
 
    { 
 
     if(!NewsCell) 
 
     { 
 
      NewsTableViewCell *cell = (NewsTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"NewsTableViewCell" forIndexPath:indexPath]; 
 
      NSDictionary *dict=dataArray[indexPath.row]; 
 
      cell.News = [dict valueForKey:@"detail"]; 
 
      [cell.NewsTableView reloadData]; 
 
      return cell; 
 
     } 
 
     return NewsCell; 
 
     
 
    } 
 
    
 
     else 
 
     { 
 
      if(!CategoryCell) 
 
      { 
 
     CategoryCell= [tableView dequeueReusableCellWithIdentifier:@"CategoryTableViewCell" forIndexPath:indexPath]; 
 
       NSDictionary *dict=dataArray[indexPath.row]; 
 
       CategoryCell.Category = [dict valueForKey:@"detail"]; 
 
       [CategoryCell.CategorycollectionView reloadData]; 
 
       return CategoryCell; 
 
      } 
 
      return CategoryCell; 
 
     } 
 
} 
 

 

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

 

 
}

+0

S'il vous plaît expliquer avec plus de détails? –

+0

Dans la photo que j'ai téléchargé les données montrent comme olx, Naukri.com, ils sont en vue de collection et des données comme Rice en toute bonté sont dans tableview je veux qu'ils les transmettent à la webview. –

+0

Ne pas implémenter didSelectRowAtIndexPath pour votre tableView principale. Au lieu de cela, créez des délégués pour TrafficCell, NewsCell, CategoryCell et gérez leurs fonctionnalités en conséquence. –

Répondre

0

Vous pouvez gérer robinet UITableViewCell la même chose que vous implémentez dans cellForRowAtIndexPath méthode

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ 
      NSDictionary *dict = dataArray[indexPath.row]; 
      UITableViewCell *cell = [tableView cellForRowAtIndexPath: indexPath]; 
      if([dict[@"type"] isEqual:@"Traffic" ]){ 
       //Find your collectionView in cell 
       //Tap on Traffic cells 
      } 
      else if([dict[@"type"] isEqual:@"News"]){ 
       //Tap on News cells 
      } 
      else { 
       //Tap on other cells 
      } 
    } 

Et cellForRowAtIndexPath vous avez besoin

TrafficCell.collectionView.delegate = self; 
CategoryCell.CategorycollectionView.delegate = self; 

pour robinet de poignée sur UICollectionViewCell et mettre en œuvre UICollectionViewDelegate méthode

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath { 
    //Tapped on your collectionViewCell inside the uitableviewcell 
} 
+0

Merci @iShashok pour cette réponse. –