Comments (17)
Hey there! Interesting idea – I honestly have never thought about putting a table view in anything other than a view controller. But yeah, I think your approach should work. Let me know if you run into trouble.
from collection-view-in-a-table-view-cell.
Hi Ash, I seem to have completed this idea (visually) however it seems as though the nested tableView's delegate methods are not being called. Unfortunately I'm not able to post code (privacy issues) and obviously this would make it difficult for you to assist, however I was wondering if you have any thoughts on the matter ?
from collection-view-in-a-table-view-cell.
I would set breakpoints/print
to make sure that the delegate/datasource properties of the table view are indeed set (and not nil
). Then I would make sure that they're set to what I expect them to be set to, which should get you there. Good luck 👍
from collection-view-in-a-table-view-cell.
my thoughts exactly - I placed 'print' inside the cellForRowAtIndexPath however this line is never executed hence making me think that the delegate method never gets called.
from collection-view-in-a-table-view-cell.
Definitely, so next you should set a breakpoint where you're setting the delegate/datasource of the table view.
from collection-view-in-a-table-view-cell.
You were right in assuming the table view delegate doesn't get set. It seems my collection view delegate method "willDisplayCell" that is executing the "setTableViewDataSourceDelegate" method is never executed (as found by break point). The only thought as to why is the warning's I receive:
- the behavior of the UICollectionViewFlowLayout is not defined because:
- the item width must be less than the width of the UICollectionView minus the section insets left and right values, minus the content insets left and right values.
-The relevant UICollectionViewFlowLayout instance is <UICollectionViewFlowLayout: 0x1390a0500>, and it is attached to <UICollectionView: 0x138140a00; frame = (-12 8; 407 494); clipsToBounds = YES; autoresize = RM+BM; gestureRecognizers = <NSArray: 0x13909fc10>; layer = <CALayer: 0x13909df10>; contentOffset: {0, 0}; contentSize: {600, 20}> collection view layout: <UICollectionViewFlowLayout: 0x1390a0500>. - Make a symbolic breakpoint at UICollectionViewFlowLayoutBreakForInvalidSizes to catch this in the debugger.
from collection-view-in-a-table-view-cell.
Hmm. Your collection view delegate should implement the following method:
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
And in there, you can set the delegate/datasource of the table view. Does that make sense?
from collection-view-in-a-table-view-cell.
Makes perfect sense - I'm already doing that. Within the delegate method i perform this method (similar to your tutorial)
collectionViewCell.setTableViewDataSourceDelegate(self, forSection: indexPath.section)
from collection-view-in-a-table-view-cell.
Is the delegate method itself getting called? Keep testing your assumptions: somewhere in there, something is not behaving as you expect. With enough trial and error, you'll find it 😸
Ash Furrow
iOS Developer, Author
http://ashfurrow.com
On Jan 13, 2016, at 11:01 PM, vTrip [email protected] wrote:
Makes perfect sense - I'm already doing that. Within the delegate method i perform this method (similar to your tutorial)
collectionViewCell.setTableViewDataSourceDelegate(self, forSection: indexPath.section)`
—
Reply to this email directly or view it on GitHub.
from collection-view-in-a-table-view-cell.
- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath
Never gets called no, which is what i was trying to get through. I have no clue why it doesn't get call, haha so weird.
from collection-view-in-a-table-view-cell.
Double check that the collection view's delegate is getting set somewhere, either in a storyboard or in a view controller?
from collection-view-in-a-table-view-cell.
Solved !!!
Turns out - after the guidance of you last comment - even though i had the delegate and datasource set in the Storyboard and the datasource set in code, I still had to set the delegate in code on the collection view.
Thank you for the assist, one last thing would be an explanation for all that. Is it common practice to have to set the delegate in code as you do with the data source ? For example.
collectionView.datasource = self
collectionView.delegate = self
When it comes to implementing a table view I'm only executing the datasource setting line. Thought this would be similar with collectionViews.
from collection-view-in-a-table-view-cell.
Hmm, no it's typical to have to set both. I'm curious why it was working with the table view – maybe they were already set, and setting only the datasource again didn't have any effect? Not sure.
Anyway, glad you got it figured out! 🎉
from collection-view-in-a-table-view-cell.
Not sure if i should open a new issue. But i have another issue.
The table view cell's are acting normally when implementing the func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)
however the delete button does not get displayed and instead is just seen as a blank white space.
from collection-view-in-a-table-view-cell.
Hmm, honestly I'm not sure. Like I said, I've not used table views outside of the context of "this table view fills the entire screen"-style. I would double-check that the code works inside a table view project by itself first, to eliminate the possibility of an error there. If it works on its own, but not in a collection view cell, then something spooky is likely going on.
from collection-view-in-a-table-view-cell.
Hi ash, just wanted to update you since you've been so helpful and I appreciate the time you have put into helping out.
Turns out everything was working fine and the reason I couldn't click the 'delete' button even though the cell would slide right to left like normal was because the collection view bounds weren't correct and caused the table view cell to be displayed off the screen.
Therefore when I would slide right to left the cell was acting accordingly however the delete button was displaying off the screen.
Again, thanks again for the assist, it's looking to be a successful integration functionality wise of a collectionView with a nested tableView in the collectionView cell's.
Best,
Vince
from collection-view-in-a-table-view-cell.
Awesome, glad everything worked out! I'm going to close this issue – feel free to re-open it or open a new one 🙇
from collection-view-in-a-table-view-cell.
Related Issues (20)
- How to perform 3D touch on collectionViews inside of TableViewCells HOT 2
- deleagte and datasource are nil HOT 1
- I was wondering how you would do this implementation without a TableviewController, but instead with a ViewController, with a tableview inside? HOT 1
- Self-sizing Cells HOT 3
- TableViewCell.swift HOT 2
- Count is performed before data is loaded HOT 2
- Custom collectionview cell content HOT 2
- collection view datasource mthod not getting called HOT 4
- collectionView cellForItemAt method is not called for xib HOT 2
- How to use Table view section id in the CollectionView Cell while deque the collection cell
- How to use Table view section id in the CollectionView Cell while deque the collection cell HOT 2
- NSInternalInconsistencyException iOS12
- setCollectionViewDataSourceDelegate in cellForRowAt instead of willDisplay? HOT 1
- Falling back to 0 when setting content offset doesn't work when there's contentInset
- I can't set the height and weight for collectionViewCell HOT 1
- Not getting collection view tag HOT 2
- You need to upgrade this from version 3 to at least 4. HOT 1
- Why should UICollectionViewDataSource be in UIViewController instead of UITableViewCell ? HOT 2
- Pagination with collection view vertical layout HOT 1
- Right To Left issue HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from collection-view-in-a-table-view-cell.