CollectionView小区代表Swift
我有带有CollectionView和uicollectionViewDataSource扩展的ViewController:
class CheckInViewController: UIViewController {
let checkInSystem = CheckInSystem()
let collectionView = UICollectionView()
viewDidAppear(){
super.viewDidAppear(animated)
checkInSystem.lala() // its function which should call delegate
}
//...
}
extension CheckInViewController: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CheckInCell.identifier, for: indexPath) as! CheckInCell
}
还有协议:
protocol AnimateTheLastCheckInDayDelegate: AnyObject{
func animateLastDay(_ cell: CheckInCell)
}
并且已经实现了
extension CheckInViewController: AnimateTheLastCheckInDayDelegate{
func animateLastDay(_ cell: CheckInCell) {
cell.backgroundColor = .red
print(1233254234) //works
}
class CheckInSystem{
weak var animateTheLastCheckInDayDelegate: AnimateTheLastCheckInDayDelegate?
func checkInScreenLaunched(){
//...
func lala(){
animateTheLastCheckInDay?.animateLastDay(CheckInCell())
}
}
我需要从 AnimAnimateThelastCheckInday?Animimatelastday(checkincell(checkincell())()。但它创建了新的单元格。如何修复?
I have ViewController with collectionView and UICollectionViewDataSource extension:
class CheckInViewController: UIViewController {
let checkInSystem = CheckInSystem()
let collectionView = UICollectionView()
viewDidAppear(){
super.viewDidAppear(animated)
checkInSystem.lala() // its function which should call delegate
}
//...
}
extension CheckInViewController: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: CheckInCell.identifier, for: indexPath) as! CheckInCell
}
Also there are protocol:
protocol AnimateTheLastCheckInDayDelegate: AnyObject{
func animateLastDay(_ cell: CheckInCell)
}
And it's realisation
extension CheckInViewController: AnimateTheLastCheckInDayDelegate{
func animateLastDay(_ cell: CheckInCell) {
cell.backgroundColor = .red
print(1233254234) //works
}
class CheckInSystem{
weak var animateTheLastCheckInDayDelegate: AnimateTheLastCheckInDayDelegate?
func checkInScreenLaunched(){
//...
func lala(){
animateTheLastCheckInDay?.animateLastDay(CheckInCell())
}
}
I need to change cell background from animateTheLastCheckInDay?.animateLastDay(CheckInCell()) . But It creates new cell. How to fix??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这将创建一个新的单元格
checkincell()
您需要通过单元格,因此请添加委托方法的实现
willdisplay
with withwith code
This creates a new cell
CheckInCell()
You need to pass the cell so add implementation for delegate method
willDisplay
With