【发布时间】:2015-11-11 19:31:44
【问题描述】:
我正在尝试设置默认的 selectedCell,默认情况下,我的意思是该单元格具有特定的 selectedCellBackgroundView。但是,即使我为它创建了一个方法,它似乎也不起作用。它没有在第一个单元格上显示任何selectedBackgroundView?当我手动选择一个单元格时它工作正常。我做错了什么?
viewDidLoad 和 viewWillAppear 都试过了
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)
标签: ios swift uitableview