2015-08-09 3 views
0

Вместо стандартного выбораStyle, где фоновый вид меняет цвет. Я пытаюсь просто изменить цвет UIView, который я добавил в guideViewCell. Однако при отмене выбора ячейки или нажатии другой ячейки она, похоже, не применяет clearColor на предыдущем индикаторе. Я попытался установить selectedBackgroundView на clearColor, но это скроет мою пользовательскую границу. Что я могу сделать, чтобы решить эту проблему?didDeSelectRowAtIndexPath не вызывается при выбореStyle none

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() 
} 
+0

проблема 'didDeSelectRowAtIndexPath' л должен быть' 'didDeselectRowAtIndexPath – 0yeoj

ответ

0

Мое решение было просто создать новую переменную и сохранить 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() 
} 
0

Вы должны быть уверены, делегат Tableview установлен и Tableview allowsSelection или allowsMultipleSelection установлен верно.