Swift3.0 UITableView/UICollectionView默认选中某个 cell

来源:互联网 发布:帖吧爆吧软件 编辑:程序博客网 时间:2024/05/17 03:50

1.tableView

//默认选中的section,rowlet defaultSelectCell = IndexPath(row: 0, section: 0)self.aTableView.selectRow(at: defaultSelectCell, animated: true, scrollPosition: UITableViewScrollPosition.none)

2.CollectionView

let defaultSelectCell = IndexPath(row: 0, section: 0)self.aCollectionView.selectItem(at: defaultSelectCell, animated: true, scrollPosition: UICollectionViewScrollPosition.left)

3.具体使用

先将tableView初始化完毕,后调用此方法将cell移动到选择的位置,在做cell的选择时,不要使用deselectRowAt方法,在选中时刷新cell.

  ///初始化默认frame    convenience init(frame: CGRect,selectRow: Int){         self.init(frame: frame)         self.selectedCell = selectRow        //默认选中的cell        let defaultCell = IndexPath(row: selectedCell, section: 0)        //默认选中        self.aTableView.selectRow(at: defaultCell, animated: true, scrollPosition: UITableViewScrollPosition.top)//移动到顶端    }
0 0
原创粉丝点击