I'm trying to set a default selectedCell and by default i mean that the cell has a specific selectedCellBackgroundView
. However even though i've created a method for it, it does not seem to work. It does not show any selectedBackgroundView
on the first cell? It works fine 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
}
tableView!.selectRowAtIndexPath(indexPath, animated: true, scrollPosition: UITableViewScrollPosition.None)