Ios 基于indexpath更新UITableView中的progressView

Ios 基于indexpath更新UITableView中的progressView,ios,swift,uitableview,uibutton,uiprogressview,Ios,Swift,Uitableview,Uibutton,Uiprogressview,我正在开发一个音频播放器应用程序,该应用程序应允许用户在UITableView中单击UITableViewCell上的按钮播放歌曲,然后他们可以在进度栏上查看歌曲的进度。我不想为每个单元格创建一个对象,我认为这会导致我失去显著的效率,因此我使用dequeueReusableCell()函数根据excel中的数据初始化单元格 出于某种原因,当我调用函数updateProgress()时(该函数应将progressView值更新为单元格的AudioPlayer的当前时间),我得到了错误: ***-[

我正在开发一个音频播放器应用程序,该应用程序应允许用户在UITableView中单击UITableViewCell上的按钮播放歌曲,然后他们可以在进度栏上查看歌曲的进度。我不想为每个单元格创建一个对象,我认为这会导致我失去显著的效率,因此我使用dequeueReusableCell()函数根据excel中的数据初始化单元格

出于某种原因,当我调用函数updateProgress()时(该函数应将progressView值更新为单元格的AudioPlayer的当前时间),我得到了错误:

***-[UITableView\u dequeueReusableCellWithIdentifier:forIndexPath:usingPresentationValues:]中的断言失败

计时器用于每.5秒运行一次updateProgres(),这是我检查
btnPressed
bool是否为true或false的方法(可能有更好的方法吗?)。我用来处理整个过程的唯一函数是segueBtn(),它在我的TableViewCell.swift类中,updateProgress()在我的TableView.swift类中,以及ViewController.swift类中的viewDidLoad()。以下是这些功能:

ViewController.swift:

override func viewDidLoad()
{
    super.viewDidLoad()
    parseCSV()
    Timer.scheduledTimer(timeInterval: 0.5, target: self, selector: #selector(FirstViewController.updateProgress), userInfo: nil, repeats: true)
}

func updateProgress() {
    if btnPressed == true {
        // Isolate Current Cell
        cell = tableView(myTableView, cellForRowAt: cellIndex) as! CustomTableViewCell
        if audioPlayer.isPlaying {
            cell.progressView.setProgress(Float(audioPlayer.currentTime/audioPlayer.duration), animated: true)
        }
        else {
            cell.progressView.setProgress(Float(audioPlayer.currentTime), animated: false)
        }
    }
}
TableViewCell.swift:

@IBAction func segueBtn(_ sender: Any) {
    do
    {
        cellIndex = (indexPath)!
        let audioPath = Bundle.main.path(forResource: songs[(indexPath?.row)!], ofType: ".mp3")
        try audioPlayer = AVAudioPlayer(contentsOf: NSURL(fileURLWithPath: audioPath!) as URL)
        audioPlayer.prepareToPlay()

        // Indicates to updateProgress() that audio player is set up
        btnPressed = true
        audioPlayer.play()
    }
    catch
    {
        print ("Audio Player was not set up correctly")
    }
}

是否有任何方法可以使用此策略更新正确单元格的progressView

cellIndex
b是否显示为全局?您的播放机可能不存在于牢房中。在视图控制器中应该有一组播放器。您的单元格应该只是ui组件;进度视图和按钮。使用委派模式使按钮返回视图控制器,并使用计时器更新可见单元格的进度条。@Paulw11谢谢,添加委派模式解决了此问题!