Iglistkit: [QUESTION] What are ListSectionController for you?

Created on 22 Jun 2017  路  6Comments  路  Source: Instagram/IGListKit

Hi guys, sorry for bothering you but I have to ask a question. What are ListSectionController for you?

Let's start from zero.
For me a section is, like we are used to, a block where you display cells under it. A UITableView or UICollectionView can have more sections.

In IGListKit seems that section are cells. At least in what I got from the IGListKitExamples project.
E.g. in MixedDataViewController

let data: [Any] = [
        "Maecenas faucibus mollis interdum. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit.",
        GridItem(color: UIColor(red: 237/255.0, green: 73/255.0, blue: 86/255.0, alpha: 1), itemCount: 6),
        User(pk: 2, name: "Ryan Olson", handle: "ryanolsonk"),
        "Praesent commodo cursus magna, vel scelerisque nisl consectetur et.",
        User(pk: 4, name: "Oliver Rickard", handle: "ocrickard"),
        GridItem(color: UIColor(red: 56/255.0, green: 151/255.0, blue: 240/255.0, alpha: 1), itemCount: 5),
        "Nullam quis risus eget urna mollis ornare vel eu leo. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.",
        User(pk: 3, name: "Jesse Squires", handle: "jesse_squires"),
        GridItem(color: UIColor(red: 112/255.0, green: 192/255.0, blue: 80/255.0, alpha: 1), itemCount: 3),
        "Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.",
        GridItem(color: UIColor(red: 163/255.0, green: 42/255.0, blue: 186/255.0, alpha: 1), itemCount: 7),
        User(pk: 1, name: "Ryan Nystrom", handle: "_ryannystrom")
]
func listAdapter(_ listAdapter: ListAdapter, sectionControllerFor object: Any) -> ListSectionController {
    switch object {
    case is String:   return ExpandableSectionController()
    case is GridItem: return GridSectionController()
    default:          return UserSectionController()
    }
}



md5-7be6eeb65051d7f01b279ddce9550cc1



```swift
let myModels: [MyModel] = [
        MyModel(title: "Maecenas faucibus mollis interdum. Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit.",
                gridItem: GridItem(color: UIColor(red: 237/255.0, green: 73/255.0, blue: 86/255.0, alpha: 1), itemCount: 6),
                user: User(pk: 2, name: "Ryan Olson", handle: "ryanolsonk")),
        MyModel(title: "Praesent commodo cursus magna, vel scelerisque nisl consectetur et.",
                gridItem: GridItem(color: UIColor(red: 56/255.0, green: 151/255.0, blue: 240/255.0, alpha: 1), itemCount: 5),
                user: User(pk: 4, name: "Oliver Rickard", handle: "ocrickard")),
        MyModel(title: "Nullam quis risus eget urna mollis ornare vel eu leo. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.",
                gridItem: GridItem(color: UIColor(red: 112/255.0, green: 192/255.0, blue: 80/255.0, alpha: 1), itemCount: 3),
                user: User(pk: 3, name: "Jesse Squires", handle: "jesse_squires")),
        MyModel(title: "Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.",
                gridItem: GridItem(color: UIColor(red: 163/255.0, green: 42/255.0, blue: 186/255.0, alpha: 1), itemCount: 7,
                                   user: User(pk: 1, name: "Ryan Nystrom", handle: "_ryannystrom"))
]
mySection = MySection(myModels: myModels)



md5-221568c88b331ca886895514b6616ec8



```swift
class MySectionController: ListSectionController {

    private var mySection: MySection

    override func numberOfItems() -> Int {
        return mySection.myModels.count
    }

    override func sizeForItem(at index: Int) -> CGSize {
        return a_size
    }

    override func cellForItem(at index: Int) -> UICollectionViewCell {
        return the_cell
    }

    override func didUpdate(to object: Any) {
        self.mySection = object as? MySection
    }
}

Is that right? I hope I'm right and the examples are wrong otherwise I'll be very confused :)

Thanks in advance for your answer, cheers!

question

All 6 comments

In my opinion, most examples show that a sectionController provides only one cell, and the diff is diffing between sections. Unless the "bind" section controller.

And you're right

@cikpis if your data is organized so that each MyModel has a title, grid item, and user, then yes you'd want to organize your data _and_ section controllers just as you have them.

The "Mixed data" demo is demonstrating how to mix different types of unrelated data into a single list.

For a demonstration of using data and dynamic sections+cells, check out this one that has a dynamic section controller (cells).

But you're right, each section controller represents a whole section that can have _n_ cells in it 馃槈

@rnystrom Great, thanks!

@rnystrom but in the link example seems that the data are threatened like sections not cells :)

in the link example seems that the data are threatened like sections not cells :)

@cikpis I'm not sure I follow. Each of these Post models will end up powering a single section in the UICollectionView (so 4 sections). Then judging by the number of comments in each, there will be a variable number of cells in each section.

My bad. I read the class by mobile phone and o didn't realize that. Sorry :)

Yes now everything is like should be :)

Thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PhilCai1993 picture PhilCai1993  路  3Comments

Przemyslaw-Wosko picture Przemyslaw-Wosko  路  3Comments

HarshilShah picture HarshilShah  路  3Comments

iwasrobbed picture iwasrobbed  路  3Comments

kleiberjp picture kleiberjp  路  3Comments