swift-从左到右显示不正确的从右到左水平集合视图

问题描述 投票:1回答:1

我正在从右到左显示水平集合视图,并遇到在显示元素时从头开始显示它们的问题(取而代之的是从左到右:]

  • 在运行模式选项中,应用程序语言设置为从右到左的伪语言
  • 如果我在启动应用程序之前添加项目,而不是在之后添加它们并调用reloadData,则不会发生此问题
  • 附带示例项目和屏幕截图

sample project

将不胜感激

在应用启动后使用reloadData添加项目的示例:example when adding the items after the app started and using reloadData

预期的行为

expected behavior

ios swift xcode uicollectionview right-to-left
1个回答
0
投票

仅在设置了delegate后才能重新加载。您必须先设置委托,然后再执行添加数据或重新加载集合的操作。

override func viewDidLoad() {
    super.viewDidLoad()
    collectionView.dataSource = self
    collectionView?.register(UINib(nibName: "CategoryCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "ReusableCell")
    let dispatchQueue = DispatchQueue(label: "resourcesQueue", qos: .background)
    dispatchQueue.async {
        self.addItems()
        DispatchQueue.main.async {
            self.collectionView.reloadData()
        } 
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.