didDeSelectRowAtIndexPath没有被调用时selectionStyle没有
问题描述:
而不是默认的selectionStyle在哪里背景视图改变颜色我试图只改变我已经添加到guideViewCell
UIView的颜色。但是,取消选中单元格或按另一个单元格时,它似乎不会将clearColor应用于之前的indicatorImage。我试图将selectedBackgroundView设置为clearColor,但是这会隐藏我的自定义边框。我能做些什么来解决这个问题?didDeSelectRowAtIndexPath没有被调用时selectionStyle没有
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("GuideCell", forIndexPath: indexPath) as! GuideViewCell
cell.selectionStyle = UITableViewCellSelectionStyle.None
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var cell = tableView.cellForRowAtIndexPath(indexPath) as! GuideViewCell
cell.indicatorImage.backgroundColor = UIColor.blackColor()
}
func tableView(tableView: UITableView, didDeSelectRowAtIndexPath indexPath: NSIndexPath) {
var cell = tableView.cellForRowAtIndexPath(indexPath) as! GuideViewCell
cell.indicatorImage.backgroundColor = UIColor.clearColor()
}
答
我的解决办法只是为了创造新的变量,并保存indexPath
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var cell = tableView.cellForRowAtIndexPath(indexPath) as! GuideViewCell
if (lastSelectedCell != nil) {
var oldCell = tableView.cellForRowAtIndexPath(lastSelectedCell!) as! GuideViewCell
oldCell.indicatorImage.backgroundColor = UIColor.clearColor()
}
lastSelectedCell = indexPath
cell.indicatorImage.backgroundColor = UIColor.blackColor()
}
答
您需要确保tableView委托被设置,并且tableView allowedSelection或allowsMultipleSelection设置为true。
问题'didDeSelectRowAtIndexPath' IR应该是''didDeselectRowAtIndexPath – 0yeoj