DenTelezhkin / DTTableViewManager

Protocol-oriented UITableView management, powered by generics and associated types.
MIT License
452 stars 48 forks source link

any advice on putting UICollectionViews into UITableViewCells? #54

Closed skydivedan closed 7 years ago

skydivedan commented 7 years ago

Sorry, this is not a bug or issue, just looking for some guidance.

There's a really good post out there detailing how to put collection-views inside of UITableViewCells. https://ashfurrow.com/blog/putting-a-uicollectionview-in-a-uitableviewcell-in-swift/

I'm trying to do something similar to this, but using DTTableViewManager (to populate UITableViewCells) and DTCollectionViewManager (for the UICollectionView that shows up inside each UITableViewCell)

My data model looks something like this:

// The number of cells in the main tableview = allDecks.count - DTTableViewManager's data source
var allDecks: [Deck]

// each UICollectionView represents a single Deck.
struct Deck {
   var cards: [Card]
}

// each cell in a UICollectionView draws a single Card
struct Card {
   var suit: Int
   var value: Int
}

Of course, the real data looks a little different. I'm using Realm for DTModelStorage, for example.

I'm just wondering if you've attempted anything like this using DTTableViewManager and DTCollectionViewManager, and might offer some advice on how best to proceed?

I'm working on a solution right now - but haven't cracked it yet. Any advice would be welcome.

DenTelezhkin commented 7 years ago

First of all, i would recommend trying to put all your data inside single UICollectionView - you can try putting each deck in it's dedicated section. If this is possible in your setup, than it will greatly simplify all efforts.

Second, if that is not possible or easy to do in your case, you can definitely put a UICollectionView inside of UITableViewCell managed by DTTableViewManager - this was actually the reason why DTTableViewManageable protocol never implies that it is a view controller. However, in this case there are several things you need to worry about:

Hope this helps you solving your task. I will close this issue as it's more a question than an issue, but you can ask more questions here if you have problems implementing this stuff.