I want to display progress view in collection view when user click on the cell and also want to display progress of that cell's progress view.
//...in .h file i have declared UIProgressView -
@property(nonatomic,retain)IBOutlet UIProgressView *pv;
//...then use it in .m file as -
I have added UIProgressView in UICollectionView's method cellForItemAtIndexPath as follows;
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"ArticleCell" forIndexPath:indexPath];
pv = [[UIProgressView alloc]init];
pv.frame = CGRectMake(45, 270, 230, 50);
pv.progress = 0.0f;
pv.progressViewStyle = UIProgressViewStyleDefault;
pv.hidden = YES;
[cell.contentView addSubview:pv];
return cell;
}
And then show progress view and its progress in didSelectItemAtIndexPath as follows;
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
//to show progressview in cell..
UICollectionViewCell *selectedCell = [collView cellForItemAtIndexPath:indexPath];
NSLog(@"subviews - %@",selectedCell.contentView.subviews);
pv = (UIProgressView *)[selectedCell.contentView.subviews objectAtIndex:0];
pv.hidden = NO;
[self performSelector:@selector(checkDownload) withObject:nil afterDelay:1.0];
}
//to check whether all images are downloaded or not and showing progress accordingly
-(void)checkDownload
{
NSError *error;
NSArray* arrArticleImages = [[NSArray alloc]init];
arrArticleImages = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:imgPath error:&error];
NSLog(@"arr cnt-%d",arrArticleImages.count );
if (arrArticleImages.count <= 8)
{
float m = (float)arrArticleImages.count / 100;
float t = pv.progress ;
float g = m + t;
pv.progress = g;
NSLog(@"prgs-%f",g);
[self performSelector:@selector(checkDownload) withObject:nil afterDelay:4.0];
}
else
{
pv.progress = 1.0;
[self insertIntoDatabase];
[self performSelector:@selector(goToNewsPaperView) withObject:nil afterDelay:2.0];
}
arrArticleImages = nil;
}
But now problem with this is that, i click on one cell it starts showing progressview with progress but as soon as click on another cell in between , the first cell's progress stops showing progress and second progress starts showing progress.
I want to display each cell's progressview's progress if it is clicked.
I think my approach is in wrong way.
I can not be able to find it out.
How can i do this??
Please help me.
Thanks..