Re: [问题] 请教关于CollectionView上面的Button。

楼主: whitefur (白毛)   2014-08-07 22:11:51
※ 引述《darktt (小朱)》之铭言:
: 不知道这个问题是否节解决了,
: 不过我最近也正在用 CollectionView,
: 所以可以做点帮忙。
: ※ 引述《kiii210 (HelloWorld!)》之铭言:
: : 建立一个mp3名称的array,顺序跟你的textView要用的array一样
: : -> @[@"song1",@"song2"];
: : 在cellForItemAtIndexPath里面给每一个button一个编号
: : -> button.tag = indexPath.row
: 其实不用这样子做,
: 只要 button.superview 就是 cell 了,
: 不过这要看 button 是否是直接加进 cell 或是 cell.contentView,
不要直接加在cell上
https://developer.apple.com/library/ios/documentation/uikit/reference/UICollectionViewCell_class/Reference/Reference.html
Do not directly add subviews to the cell itself.
The cell manages multiple layers of content,
of which the content view is only one.
In addition to the content view,
the cell manages two background views
that display the cell in its selected and unselected states.
所以也不要用superview来取cell
可以参考#1IzPAnIP
虽然那篇讲的是tableViewCell
不过我想collectionViewCell应该有异曲同工之妙
每一个版本的cell view hierarchy都可能会更动
: 不管哪一个只要一直用 superview 就可以取得上一层的 view。
: 就像是这样子
: UIView *cellContentView = button.superview;
: UICollectionViewCell *cell = (UICollectionViewCell *)cellContentView.superview;
: UICollectionView *collectionView = (UICollectionView *)cell.superview;
: 只要这样子就能知道 cell 所属的 indexPath 了,
: 这样子也不会出现因为 button 的 tag 被 reuse 而设定错误的问题了。
: 另外,AVPlayer 有另外一个 AVQueuePlayer 可以使用来播放多个音乐或影片,
: 这样子可以解决播放的问题。
作者: darktt (小朱)   2014-08-07 22:32:00
那就只能用tag去抓cell的实体?
作者: kiii210 (HelloWorld!)   2014-08-07 22:41:00
不用抓cell呀, button上设tag, 从selector的sender抓就好要抓cell应该用cellForRowAtIndexPath比较好?话说原原po的问题已经解决了~

Links booklink

Contact Us: admin [ a t ] ucptt.com