Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not handle tableview with multiple sections #4

Open
lnjustin opened this issue Dec 1, 2015 · 5 comments
Open

Does not handle tableview with multiple sections #4

lnjustin opened this issue Dec 1, 2015 · 5 comments

Comments

@lnjustin
Copy link

lnjustin commented Dec 1, 2015

This code relies on the tag property. Because of this, it does not account for tableviews with multiple sections. How would you modify the code to account for this? Could you create a custom UICollectionView with custom properties "section" and "row", and store the tableview section and row in those properties? Would that violate MVC? Thanks!

@ashfurrow
Copy link
Owner

Great question! I did this once before, basically I just subclassed UICollectionView to add a property to store the index (before I used tag). You could use the same technique to store an index path instead, or use ObjC's associated objects, but I wouldn't recommend it 😉

Does that make sense?

@PPacie
Copy link

PPacie commented Dec 12, 2015

Hi guys,

I could make the UITableView sections work without subclassing the UICollectionView nor adding new properties. Just used indexPath.section instead of indexPath.row in the tableView willDisplayCell: method:

tableViewCell.setCollectionViewDataSourceDelegate(self, forRow: indexPath.section)

PS: Of course you will also need to add the UITableView delegate methods to indicate the number of sections, title, etc.

Hope it helps, any doubts just let me know.

@dinhcuong1989
Copy link

i tried to get different Data for uicollectionView but it didn't work.

in TableView
tableViewCell.setCollectionViewDataSourceDelegate(self, forRow: indexPath.section)

in CollectionView
if (indexPath.section == 0) {
cell.titleItem.text = self.songName[indexPath.row]
}

    if (indexPath.section == 1) {
        cell.titleItem.text = self.songUrl[indexPath.row]
    }

it showed same text every section in tableView

@PPacie
Copy link

PPacie commented Mar 25, 2016

In the collectionView you should have something like this:

cell.titleItem.text = self.songURL[collectionView.tag][indexPath.item]

I don't think you need to check for the indexPath.section == 1 there.

Hope it works for you.

@mujtuba11khan
Copy link

Hi guys,

I could make the UITableView sections work without subclassing the UICollectionView nor adding new properties. Just used indexPath.section instead of indexPath.row in the tableView willDisplayCell: method:

tableViewCell.setCollectionViewDataSourceDelegate(self, forRow: indexPath.section)

PS: Of course you will also need to add the UITableView delegate methods to indicate the number of sections, title, etc.

Hope it helps, any doubts just let me know.

How did you used that table section then inside the collectionView method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants