2

I have a horizontally scrolling NSCollectionView. The items are created but it is not scrollable until I manually resize the window in a horizontal direction. After that I scrolls fine. Does anybody know how to fix this? I looked at this question (question link) and tried the suggested solutions but I think its a different problem since it works after resizing the window.

EDIT: The collection view is in a tableview cell. I have other collection views (although vertically scrolling and not in a tableview cell) in the same application and they work fine.

user2403221
  • 435
  • 1
  • 3
  • 12
  • Does this answer your question? [NSCollectionView does not scroll items past initial visible rect](https://stackoverflow.com/questions/46433652/nscollectionview-does-not-scroll-items-past-initial-visible-rect) – strangetimes Apr 17 '21 at 11:23

2 Answers2

1

I solved it just by add this on my collectionView:

[self.yourCollectionView setFrameSize:self.yourCollectionView.collectionViewLayout.collectionViewContentSize];
JJJ
  • 32,902
  • 20
  • 89
  • 102
0

I been experiencing similar issue for so many years and finally figured out that this is caused by Xcode.

When force quitting your application with Xcode (by ether clicking Run or Stop when application is running), Xcode saves the window's frame and restore it on next launch, even when your window is not configured to autosave its frame.

This is good for development but for some reasons, this causes the document view of the scroll view (mostly collection view) to not use the correct bounds in the next application run.

Manually setting collection view's frameSize as many people suggested doesn't always works. However, if you quit your application normally:

  • Click Application Menu and select Quit Application Name
  • Use keyboard shortcut ⌘Q
  • Right click on Dock icon and select Quit (with or not)
  • Force quit in Force Quit Applications window (⌘⌥⎋)
  • ...

Anything will works as you expected in the next application run (including launching from Xcode).

ix4n33
  • 526
  • 4
  • 10