I have 6 cells in a UICollectionView
.I would like to change the images in each UICollectionViewCell
after a particular interval.How is it possible?
Asked
Active
Viewed 163 times
1

Bhavin Ramani
- 3,221
- 5
- 30
- 41

Akhil Jiji
- 185
- 1
- 2
- 13
-
Do you want to change the image on each cell at once..or one at a time? – Bista Dec 31 '15 at 06:52
-
1I want to change the image on each cel at once. – Akhil Jiji Jan 05 '16 at 09:16
4 Answers
2
You can do it like this:
[NSTimer scheduledTimerWithTimeInterval:10.0f
target:self
selector:@selector(updateImage:)
userInfo:nil
repeats:YES];
- (void)updateImage
{
[yourImageview setImage:[UIImage imageWithName:@"image1"]];
[yourCollectionView reloadData];
}

Yunus Nedim Mehel
- 12,089
- 4
- 50
- 56

chirag bhalara
- 203
- 1
- 10
-
-
*yes you can but collectionview reload is best way * Here is an example to find image view with tag for (UIImageView *imgView in collectionView.subviews) { if ([imgView isKindOfClass:[UIImageView class]]) { if(imgView.tag == 1//any tag which you want) [imgView setImage:[UIImage imageWithName:@"image1"]]; } } – chirag bhalara Jan 05 '16 at 09:48
0
Reload the UICollectionView
. It will call delegate methods of CollectionView
& write your logic over there.

Nilesh Patel
- 6,318
- 1
- 26
- 40
0
//Write this to viewDidLoad
self.timer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(AutomaticScroll) userInfo:nil repeats:YES];
//Add this method to the class
-(void)AutomaticScroll
{
if (i<[imgArray count])
{
NSIndexPath *IndexPath = [NSIndexPath indexPathForRow:i inSection:0];
[self.collectionView scrollToItemAtIndexPath:IndexPath
atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
i++;
if (i==[imgArray count])
{
i=0;
}
}
}

psk
- 162
- 1
- 13
0
3 Steps:
- Set a Timer
- Shuffle Array
- Refresh Collection View
Step 1 : Set a Timer
[NSTimer scheduledTimerWithTimeInterval:2.0f
target:self
selector:@selector(shuffleView:)
userInfo:nil
repeats:YES];
Step 2: Shuffle Array
Here I found a nice solution on how to shuffle the array using Category:
What's the Best Way to Shuffle an NSMutableArray?
Step 3: Reload Collection View
- (void)shuffleView
{
[MyArray shuffle];
[yourCollectionView reloadData];
}