如何处理didSelectRowAtIndexPath方法,使其适用于在它的每个cell都在三个不同的cell?

qq_24434367 2016-08-02 02:19:32
- (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
{


}
...全文
223 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuxiangxiong2 2016-08-03
  • 打赏
  • 举报
回复
你可以在didselect方法中通过对dataarray来判断选中的是哪个cell,
japper520 2016-08-03
  • 打赏
  • 举报
回复
两种正常的办法: 1.最正常的办法:适用于页面是静态的不会有改变,直接判断indexpath的row和section来写点击事件 2.也可以用的办法:适用于每个cell动态创建但保有指针的情况,可以判断一个 cell是否等于被点击的cell(调用cellForRowAtIndexPath这个方法就能得到被点击的cell的指针了),如果是就做处理
qq_35270459 2016-08-02
  • 打赏
  • 举报
回复
你在创建cell的时候 是根据dataArray和indexPath来创建不同的cell, 那你在点击的时候也可以用dataArray和indexPath来判断点的是哪个cell

29,028

社区成员

发帖
与我相关
我的任务
社区描述
主要讨论与iOS相关的软件和技术
社区管理员
  • iOS
  • 大熊猫侯佩
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧