你需要保持当前单元格的indexPath在VAR:
var currentlyActiveCellIndexPath: IndexPath
当用户选择一个单元格,设置currentlyActiveCellIndexPath给该小区的indexPath(虽然这取决于你如何开始一切都关掉 - 你可能不需要这个,如果你与第一小区,例如自动启动,那么你只设置currentlyActiveCellIndexPath到IndexPath(项目:0,部分:0))
func collectionView(_ collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: IndexPath) {
self.currentlyActiveCellIndexPath = indexPath
// etc, etc
}
您需要实现某种委托模式(单元呼叫的地方)一个方法在它的委托上)让你的控制代码知道这首歌已经完成,&当它接到电话时,只需调用你在下一个单元格上创建的函数,你可以通过增加indexPath的项目来找到它。例如 -
// delegate method called by cell
func songDidFinish() {
self.currentlyActiveCellIndexPath.item += 1
// Obviously you'll have to use whatever class you've created your cells as here, with the relevant methods, etc.
if let nextCell = self.collectionView.cellForItem(at: self.currentlyActiveCellIndexPath) as? SongPlayingCell {
nextCell.startPlaying()
}
}
推测,当一个单元格停止播放时,它可以设置自己的状态。
如果你不确定如何使用代表,那是另一个问题,&有很多关于这方面的信息。
在我看来你的问题太普遍 – Robert
创建IndexPath类型的三个变量:currentlyPlaying,previouslyPlayed和nextPlayable。每次你更新当前正在播放的歌曲,更新VC中的所有三个索引路径。 –
如果你问一个问题,你应该保持它的更新,关于你是否找到了答案,或者实际上使用了某人为你发布的答案。否则,人们会在你的历史中看到你不接受答案,他们会停止回答。 – SomaMan