我正在继续针对iOS的应用程序导向至iPad。今天早上asked a question在我的问题得到正确答案的网站上。但由于某种原因,阿尔法在我的桌子的单元格中不起作用。Alpha无法在UITableViewCell中工作
这是我的看法关系的TableView:
这是我的银行代码:
import UIKit
class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
let data:[String] = ["Row 0","Row 1", "Row 2","Row 3","Row 4","Row 5","Row 6"]
@IBOutlet var tableView: UITableView!
var rowSelected:Int! = nil
override func viewDidLoad() {
super.viewDidLoad()
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:Cell = self.tableView.dequeueReusableCellWithIdentifier("cell") as! Cell
if rowSelected != nil {
if rowSelected > indexPath.row {
cell.alpha = 0.7
} else if rowSelected == indexPath.row {
cell.alpha = 1.0
} else {
cell.alpha = 0.3
}
}
cell.labelText.text = self.data[indexPath.row]
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
self.rowSelected = indexPath.row
tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic)
}
}
当我选择一排,没有任何反应,阿尔法没有。在这个例子中,我直接在单元格中应用Alpha(我禁用了单元格中的不透明选项 - 单元格不透明)。 在原始应用程序中,我有2个标签,2个按钮和一张图片。为了更实际,Alpha的必要性直接用于Cell。
有人可以帮我吗?
为什么当你选择一行时你期望有什么改变?您发布的代码只会更新所选行,并且所选行的设置为1.0。每当选择一行时,您应该重新加载所有可见的行。 – rmaddy
@rmaddy当选择一行时,我需要做什么来改变所有单元格的Alpha(1.0/0.7/0.5)? – James
对。这就是为什么我说你选择一行时需要重新加载所有可见单元格的原因。您只重新加载选定的单元格。 – rmaddy