我有一个包含多个单元格的 tableview,每个单元格都有 tableview、collectionview、tableview,就像那样

I am having a tableview with multiple cell in it and in each cell having tableview, collectionview, tableview, like that

如何处理 didSelectRowAtIndexPath 以便它适用于其中每个单元格的所有三个不同单元格?

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
{


}

您可以像在 cellForRowAtIndexPath 方法

中实现的那样处理 UITableViewCell 上的点击
- (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
           }
    }

而在 cellForRowAtIndexPath 你需要

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

用于处理点击 UICollectionViewCell 并实施 UICollectionViewDelegate 方法

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