【发布时间】:2017-07-31 10:04:42
【问题描述】:
我正在尝试在以这种方式加载视图时设置默认项:
override func viewDidLoad() {
super.viewDidLoad()
self.collectionView.delegate = self
self.collectionView.dataSource = self
self.collectionView.allowsSelection = true
self.collectionView.allowsMultipleSelection = true
}
我正在尝试在viewDidAppear 方法中选择一个项目:
override func viewDidAppear(_ animated: Bool) {
DispatchQueue.main.async(execute: {
self.collectionView.selectItem(at: IndexPath(item: 0, section: 0), animated: true, scrollPosition: UICollectionViewScrollPosition.bottom)
})
}
但是 didSelectItemAt 方法并没有像我需要的那样被触发。
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath){
//some config
}
我是不是忘记了什么?
【问题讨论】:
标签: ios swift uicollectionview uicollectionviewcell