Iglistkit: How to insert new section controller within the visible section controllers

Created on 23 Mar 2017  路  2Comments  路  Source: Instagram/IGListKit

I have a trigger that needs to insert a section controller somewhere in between the currently visible section controllers on screen. I can get the visible section controllers and their objects, however, I am unable to find their indices.

I'm trying something like this:

//model.content is [IGListDiffable]
let visibleControllers = adapter.visibleSectionControllers()
if let firstController = visibleControllers.first {
    let section = adapter.section(for: firstController)
    if let object = adapter.object(atSection: section) as? IGListDiffable,
        let index = model.content.index(of: object) { // Doesn't work
        ...
    }
}

But you can't use index(of:) with an IGListDiffable array. How can I do this? Thanks!

question

All 2 comments

@yusuftor you already have the indices by getting the section of the section controller 馃槈

let section = adapter.section(for: controller)
let object = adapter.object(at: section)
// or
let object = adapter.objects()[section]

If you're trying to find the indices of the _items within the section controller_ that is a different story. Lmk if that is what you're trying to do. If that's the case, you should be doing that work inside the section controller.

Oops 馃槵 Thanks!

Was this page helpful?
0 / 5 - 0 ratings