Giter VIP home page Giter VIP logo

Comments (17)

ashfurrow avatar ashfurrow commented on June 19, 2024

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.

vTrip avatar vTrip commented on June 19, 2024

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.

ashfurrow avatar ashfurrow commented on June 19, 2024

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.

vTrip avatar vTrip commented on June 19, 2024

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.

ashfurrow avatar ashfurrow commented on June 19, 2024

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.

vTrip avatar vTrip commented on June 19, 2024

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.

ashfurrow avatar ashfurrow commented on June 19, 2024

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.

vTrip avatar vTrip commented on June 19, 2024

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.

ashfurrow avatar ashfurrow commented on June 19, 2024

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.

vTrip avatar vTrip commented on June 19, 2024

- (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.

ashfurrow avatar ashfurrow commented on June 19, 2024

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.

vTrip avatar vTrip commented on June 19, 2024

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.

ashfurrow avatar ashfurrow commented on June 19, 2024

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.

vTrip avatar vTrip commented on June 19, 2024

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.

ashfurrow avatar ashfurrow commented on June 19, 2024

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.

vTrip avatar vTrip commented on June 19, 2024

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.

ashfurrow avatar ashfurrow commented on June 19, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.