我有一个tableview与多个单元格在它和每个单元格有tableview,collectionview,tableview,就像那
问题描述:
如何处理didSelectRowAtIndexPath,以便它可以在它的每个单元格的所有三个不同的单元格上工作?我有一个tableview与多个单元格在它和每个单元格有tableview,collectionview,tableview,就像那
- (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
{
}
答
您可以处理水龙头上UITableViewCell
一样的,你在cellForRowAtIndexPath
方法实现
- (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
}
+0
感谢@iShashok为此答复。 –
请更多的细节解释一下吗? –
在我上传的图片中,像olx,Naukri.com这样的数据显示出来,他们在收集视图和像Rice这样的数据都在tableview中,我希望他们能够将它们传递给webview。 –
不要为主tableView实现didSelectRowAtIndexPath。相反,为TrafficCell,NewsCell,CategoryCell创建委托并相应地处理其功能。 –