美文网首页
获取cell的两种方式

获取cell的两种方式

作者: 06f43b0b52f7 | 来源:发表于2018-08-01 18:27 被阅读264次

UItableViewCell

第一种方式

  • 经常用的方式获取cell
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:_btn.tag-100 inSection:0];

UITableViewCell *cell = [_tableView cellForRowAtIndexPath:indexPath];

第二种方式

cell子视图获取

  • 在自定义cell的时候,在cell上添加了一个button,然后在controller中调用这个button的时候要获取到cell,在iOS6中直接button.superView就可以。
  • 但是iOS7中不行,发现iOS7第一次的superview只能取到cell的contentView,也就说得取两次,但是结果发现还是不行,取两次竟然才取到cell的contentView层,不得已取三次superview实现。
  • 但是更新iOS8之后的调用发现崩溃···检查发现三次取superview竟然取多了,到tableview层上了。也就是说iOS8就是得取两次。
iOS6取一次superview就行,也即 button.superView
iOS7取三次superview,也即 button.superView.superView.superView
iOS8取两次superview,也即 button.superView.superView

相关文章

网友评论

      本文标题:获取cell的两种方式

      本文链接:https://www.haomeiwen.com/subject/txgrvftx.html