Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialGregg Mojica
11,506 PointsLoop Through Cells in UITableView
Hey Guys!
So I'm working on a project right now involving a UITableView. I have the cells' alpha initially set to 0 and want each cell to appear about 1 second after the other. I imagine I would need to loop through the array of tableviewcells. Any ideas? Amit Bijlani
Thanks!
2 Answers
Kai Aldag
Courses Plus Student 13,560 Pointshello greg,
what I would do is when you create the cells (in cellForRowAtIndexPath) set the cells alpha to 0 then set it to one in an animation block, it should look something like this
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
cell.alpha = 0;
[UIView animateWithDuration:1 animations:^{
cell.alpha = 1.0;
}];
}
this is the first thing that comes to mind, let me know if it works.
Best, Kai.
Gregg Mojica
11,506 PointsThank you so much! The second answer works fantastic!
Kai Aldag
Courses Plus Student 13,560 PointsNo problem :)
Gregg Mojica
11,506 PointsGregg Mojica
11,506 PointsThanks, while that does work, it's not what I'm looking for. That code makes all the cells in the tableview fade in at the same time - I need each cell to fade in about 0.5 to 1 second after the previous.
Kai Aldag
Courses Plus Student 13,560 PointsKai Aldag
Courses Plus Student 13,560 Pointsaha i thought you might say that so I thought of doing something like this
try that and let me know if it works
Let me know if this works, Kai
Kai Aldag
Courses Plus Student 13,560 PointsKai Aldag
Courses Plus Student 13,560 Pointsthis might or might not work, if it doesn't try something like
this might work, anyways call this method once all cells are made,
Best, Kai