Daily iOS
UIKit

Linked collection and table scrolling

A contacts screen in code review. A horizontally scrolling UICollectionView of letter indexes sits on top, a sectioned UITableView of contacts below; scrolling the table should select the matching index on top, and tapping an index should scroll the table to that section. How would you find and fix the bug where the two directions trigger each other and bounce back and forth forever?

How would an interviewer hear this answer? You'll see whether they'd move on, dig in, or say no, and which sentences would trip you up. Your score doesn't change.
See the short answer

Break the loop where a table scroll selects an index and that selection scrolls the table again with a flag that marks a programmatic scroll in progress, and clear the flag in scrollViewDidEndScrollingAnimation.

Share a question