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

Reverse functionality #9

Closed
vTrip opened this issue Jan 12, 2016 · 17 comments
Closed

Reverse functionality #9

vTrip opened this issue Jan 12, 2016 · 17 comments

Comments

@vTrip
Copy link

vTrip commented Jan 12, 2016

Was wondering about doing the opposite of this and having a tableview nested inside a collection view cell. would it just be replacing the tableview delegates with the collection view and making the tableView delegates the extension of the class ?

@ashfurrow
Copy link
Owner

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.

@vTrip
Copy link
Author

vTrip commented Jan 13, 2016

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 ?

@ashfurrow
Copy link
Owner

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 👍

@vTrip
Copy link
Author

vTrip commented Jan 13, 2016

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.

@ashfurrow
Copy link
Owner

Definitely, so next you should set a breakpoint where you're setting the delegate/datasource of the table view.

@vTrip
Copy link
Author

vTrip commented Jan 13, 2016

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.

@ashfurrow
Copy link
Owner

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?

@vTrip
Copy link
Author

vTrip commented Jan 14, 2016

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)

@ashfurrow
Copy link
Owner

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 notifications@github.com 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.

@vTrip
Copy link
Author

vTrip commented Jan 15, 2016

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

@ashfurrow
Copy link
Owner

Double check that the collection view's delegate is getting set somewhere, either in a storyboard or in a view controller?

@vTrip
Copy link
Author

vTrip commented Jan 15, 2016

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.

@ashfurrow
Copy link
Owner

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! 🎉

@vTrip
Copy link
Author

vTrip commented Jan 17, 2016

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.

@ashfurrow
Copy link
Owner

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.

@vTrip
Copy link
Author

vTrip commented Jan 20, 2016

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

@ashfurrow
Copy link
Owner

Awesome, glad everything worked out! I'm going to close this issue – feel free to re-open it or open a new one 🙇

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

2 participants