Narendra Pandey Narendra Pandey - 7 months ago 47
Objective-C Question

Scroll one cell at a time in collection View

With The Help Of willDisplay Method i got the last index of visible cell

- (void)collectionView:(UICollectionView *)collectionView willDisplayCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath

IndexVisibleCell = [indexPath indexAtPosition:[indexPath length] - 1];

where IndexVisibleCell is NSUInteger that is declared in interface. My problem is that i want to shift only one cell when user click on Right Button or left Button. i have applied this code for that Purpose.

NSUInteger indexOfScrolledCell;
indexOfScrolledCell = IndexVisibleCell;

if (IndexVisibleCell<9)

NSIndexPath *path = [NSIndexPath indexPathForRow:indexOfScrolledCell+1 inSection:0];

[self.obj_CollectionView1 scrollToItemAtIndexPath:path atScrollPosition:UICollectionViewScrollPositionLeft animated:YES];



as i show 3 cell at a time. By using that action method of Right click there is shifting of 3 cell at a time not one. so please help me how to scroll one cell at time.


Use visibleCells to get your visible Cells, get the left most Cell index to figure out the next index, then scroll to that Cell on the left (similar logic to your code).
willDisplayCell is not reliable since it is called both times when you scroll left/right, and you're thinking that index is the left/right most is not correct.

Or you need to compare the index in willDisplayCell correctly, to get the correct left/right most index, based on your logic.