I am trying to set defaultCell and by default I mean that the cell has a specific one selectedCellBackgroundView. However, despite the fact that I created a method for it, it does not seem to work. Does he not show selectedBackgroundViewin the first cell? It works great when I select a cell manually. What am I doing wrong?
viewDidLoad and viewWillAppear tried both
let indexPath = NSIndexPath(forRow: 0, inSection: 0)
let cell = tableView!.cellForRowAtIndexPath(indexPath)! as UITableViewCell
applySelectionChangesToCell(cell)
didSelectRowAtIndexPath
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let cell = tableView.cellForRowAtIndexPath(indexPath)! as UITableViewCell
applySelectionChangesToCell(cell)
NSUserDefaults.standardUserDefaults().setInteger(menuArray[indexPath.row].id!, forKey: "leagueId")
self.sideMenuViewController.hideMenuViewController()
}
applySelectionChangesToCell
func applySelectionChangesToCell(cell:UITableViewCell) {
let backgroundSelectionView = UIView(frame: cell.bounds)
backgroundSelectionView.backgroundColor = UIColor.whiteColor().colorWithAlphaComponent(0.1)
cell.selectedBackgroundView = backgroundSelectionView
}
source
share