私のアプリでは、テーブルビューとカスタムセルがあり、ラベル、ボタン、およびprogressBarがあるので、ボタンを押すとprogressBarが進捗状況を表示しますが、スクロールするとそこにあることがわかります他のセルが選択され、進捗状況が表示されます。また、スクロールアップすると、選択したセルの進行状況が停止します。あなたは助けることができる、任意のフィードバックが私のTableViewControllerだこと)タップされたセルだけをボタンで選択する方法は?
を感謝:
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return titles.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell
{
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! ViewControllerTableViewCell
cell.pesnya.text = titles[indexPath.row]
cell.pevets.text = artists[indexPath.row]
cell.url = urls[indexPath.row]
return (cell)
}
@IBAction func buttonPressed(_ sender: AnyObject) {
(sender as! UIButton).isSelected = !(sender as! UIButton).isSelected
if (sender as! UIButton).isSelected {
if let indexPath = tableView.indexPath(for: sender.superview!?.superview as! UITableViewCell) {
DownloadManager.shared.download(url: urls[indexPath.row], title: titles[indexPath.row])
}
} else {
// (sender as! UIButton).setTitle("Удалить", for: UIControlState.normal)
if let indexPath = tableView.indexPath(for: sender.superview!?.superview as! UITableViewCell) {
let name = "\(titles[indexPath.row]).mp3"
let name2 = name.replacingOccurrences(of: " ", with: "")
let filePathURL = URL(string:"string")
do {
try FileManager.default.removeItem(at: filePathURL!)
} catch {
print("Could not delete file: \(error)")
}
}
}
}
あなたがデータソースにあなたのボタンの状態を保存する必要があります。 – Jaydeep