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