0506 后去cell

//         UICollectionViewCell *cell = [collectionView cellForItemAtIndexPath:indexPath];

 

//        MCLog(@"cell =%zd,=cell frame%@",index,NSStringFromCGRect(cell.frame));

 

2:

获取tableview的cell

 (2012-11-05 19:42:06)
标签: 

杂谈

 
 

在这个例子中,当改变picker值的时候,Cell中的值也跟着改变。以前就一直很纠结怎么获取选中的Cell,看过这个例子后,真是豁然开朗呀!

这个例子里用到了一个方法:indexPathForSelectedRow,用这个方法就能获取选择的cell了--!以前怎么没发现...

关键代码:

- (IBAction)dateAction:(id)sender{

 //这样就把选择的cell找出来了?真经典orz

 NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];

 UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];

 cell.detailTextLabel.text= [self.dateFormatter stringFromDate:self.pickerView.date];

[self.tableView deselectRowAtIndexPath:indexPathanimated:YES];//注意!这句话可不能再放在didselected...的那个方法里

 }

补充问题:以上方法只有在点击cell时才能确定cell的index,而如果点击了cell上的button,用上面的方法还是没办法解决。

解决办法:由按钮获得它SuperView,即你自己定义的cell,知道这个cell了后在得到它的行数。

原文地址:https://www.cnblogs.com/gzz2016/p/5464797.html