我正在编写一个基于UICollectionView和RxSwift/RxCocoa的小型图像查看器,以提供委托功能。我的目标是在从viewModel加载数据之后立即跳转到某个单元格。这是我到目前为止尝试过的。
ViewModel:
class ImageViewerViewModel {
let dataSource = BehaviorRelay<[UIImage]>(value: [])
let selectedImageIndex = BehaviorSubject<Int>(value: 0)
private let disposeBag
我在iOS 10上得到了这个错误,但是它在iOS 11和iOS 9上都运行得很好。
*终止应用程序由于非正常异常'NSRangeException',原因:'* -__NSArrayM objectAtIndex::索引5超出界限0。4‘
这是我的代码:
let indexPath = IndexPath(row: index, section: 0)
print(indexPath.row) // 5
//here is the problem. I got 6 items in my datasource but looks like collectionView
我正在运行代码,以便在swift iOS聊天应用程序中加载聊天。聊天应用程序中的问题是在运行应用程序时,函数paginateData()中的"query in else{}“,第一个"query in if{}”如预期的那样顺利运行,但在另一个函数中没有运行。我正在使用firestore数据库来实现聊天。我的目标是对聊天室的聊天进行分页。如果需要更多信息,请告诉我。 代码 func paginateData() {
fetchingMore = true
var query: Query!
if messages.isEmpty {
我有一个自定义的collectionView布局。此自定义布局增加了中心单元格的宽度。下面是执行此操作的自定义布局类。查看shiftedAttributes函数,了解它是如何完成的
class CustomCollectionViewLayout: UICollectionViewLayout {
private var cache = [IndexPath: UICollectionViewLayoutAttributes]()
private var contentWidth = CGFloat()
private var visibleLayoutAttribu
为什么scrollToItem不在我的CollectionView里工作?我想在scrollToItem的EnabledID上工作。那么,有什么问题,如何解决呢?
代码:
var dataArray = NSMutableArray() // dataArray is has a data from Database
var EnabledID = Int()
EnabledID = UserDefaults.standard.integer(forKey: "EnabledID")
if EnabledID == 0 {
EnabledI
我在视图控制器中使用UICollectionView,并传递了一个图像数组。我已经启用了集合视图的分页。但是当我滚动到下一个图像时,前一个单元格并没有完全消失。它仍然在边缘。所以,how I can make only specific image/cell visible while scrolling left/Right.
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if coll
当我在模拟器上运行时,它工作正常。但是当我在物理设备上运行时,我面临一个错误-- index out of range。
代码:
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
let index = NSIndexPath(row: 0, section: 0) as IndexPath
resultController?.collectionView?.scrollToItem(at: index, at: .bottom, ani