Collection View
Collection View
View.h
View.h
<UICollectionViewDelegate,UICollectionViewDataSource>
IBOutlet UICollectionView *Vw_Collect;
View.m
[Vw_Collect setDelegate:self];
[Vw_Collect setDataSource:self];
[Vw_Collect setBackgroundColor:[UIColor groupTableViewBackgroundColor]];
UINib *cellNib = [UINib nibWithNibName:@"Task_FloreCollectionViewCell" bundle:nil];
[Vw_Collect registerNib:cellNib forCellWithReuseIdentifier:reuseIdentifier];
#pragma mark -- CollectionViewDataSource
//Collectionview Methods
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return ValArr2.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
Task_FloreCollectionViewCell * cell = [[Task_FloreCollectionViewCell alloc]init];
cell = nil;
if (cell == nil)
{
cell=(Task_FloreCollectionViewCell*)[collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
}
else if (cell.Img_Flore == nil)
{
cell=(Task_FloreCollectionViewCell*)[collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
}
cell.Lbl_Flore_Title.hidden = YES;
cell.Lbl_Flore_Title.text = [[ValArr2 valueForKey:@"cfp_floor"] objectAtIndex:indexPath.row];
NSString *url=[NSString stringWithFormat:@"%@%@",FloreImageURL,[[ValArr2 valueForKey:@"cfp_img"] objectAtIndex:indexPath.row]];
NSLog(@"url %@",url);
[cell.Img_Flore setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"FireLogoRED"] usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"hello i'm selected");
FloreViewController *FloreView = [[FloreViewController alloc] initWithNibName:@"FloreViewController" bundle:nil];
NSLog(@"vallll %@",ValArr2);
FloreView.ImageLink = [[ValArr2 valueForKey:@"cfp_img"] objectAtIndex:indexPath.row];
FloreView.ImagelinkArr = [ValArr2 valueForKey:@"cfp_img"];
[self presentViewController:FloreView animated:YES completion:nil];
}
#pragma mark -- CollectionViewDelegateFlowLayout
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake((self.view.frame.size.width / 2) - 6, (self.view.frame.size.width / 2) - 25);
}
Comments
Post a Comment