Reputation: 185
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?
Upvotes: 1
Views: 167
Reputation: 7903
3 Steps:
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];
}
Upvotes: 0
Reputation: 192
//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;
}
}
}
Upvotes: 0
Reputation: 203
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];
}
Upvotes: 2
Reputation: 6394
Reload the UICollectionView
. It will call delegate methods of CollectionView
& write your logic over there.
Upvotes: 0