我的 tableView 有一个奇怪的问题。我有一个音轨列表和一个音频播放器的序列,以便在特定行播放选定的轨道。一切正常!
我想更改表格中所选行的背景颜色,这样,一旦用户播放音频并返回到曲目列表(我的表格视图控制器),他就可以看到哪些是先前选择的行。
但是当我运行它时,它不仅改变了我选择的索引路径处的行的颜色,还改变了索引路径 + 10 处的项目的颜色。如果我选择第一行,它会改变索引处行的颜色:0, 10、20、30...
为了更改所选单元格的颜色,我执行了以下操作:
// MARK: - Navigation
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.performSegueWithIdentifier("audioPlayer", sender: tableView)
var selectedCell:UITableViewCell = tableView.cellForRowAtIndexPath(indexPath) as CustomTableViewCell
selectedCell.contentView.backgroundColor = UIColor.greenColor()
selectedCell.backgroundColor = UIColor.blueColor()
请找到我的问题的屏幕截图,我只选择了三行:1、3、5,但我选择了 1、3、5、11、13、15、21、23 等等...: https:// www.dropbox.com/s/bhymu6q05l7tex7/problemaCelleColore.PNG?dl=0
有关更多详细信息 - 如果可以提供帮助 - 这是我的自定义表视图类:
import UIKit
class CustomTableViewCell: UITableViewCell {
@IBOutlet weak var artista: UILabel!
@IBOutlet weak var brano: UILabel!
var ascoltato = false
@IBOutlet weak var labelRiproduciAscoltato: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
func setCell(artista: String, brano: String){
self.artista.text = artista
self.brano.text = brano
}
} // END MY CUSTOM TABLE VIEW CELL
这是我的 TableViewController 中的方法 cellForRowAtIndexPath:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = self.tableView.dequeueReusableCellWithIdentifier("tableCell", forIndexPath: indexPath) as CustomTableViewCell
var tracks : Brani //Brani is my custom Object for handle my tracks
cell.setCell(tracks.title!, brano: tracks.author!)
return cell
}
我在装有 iOS 7.1 的 iPad Air 上运行。
预先感谢您对我的问题提出任何建议或意见。