Skip to content

Instantly share code, notes, and snippets.

@tariqul000
Created November 23, 2016 08:51
Show Gist options
  • Save tariqul000/3aca96843f5392d8173880661560b1de to your computer and use it in GitHub Desktop.
Save tariqul000/3aca96843f5392d8173880661560b1de to your computer and use it in GitHub Desktop.
Collection VIew
//
// ViewController.m
// CollectionViewExample
//
// Created by User on 11/23/16.
// Copyright © 2016 Vu Mobile. All rights reserved.
//
#import "ViewController.h"
#import "TopCell.h"
#import "BottomCell.h"
#import "AFHTTPSessionManager.h"
@interface ViewController ()
@end
@implementation ViewController
NSMutableArray *SelfiThemeImage ;
NSMutableArray *SelfiThemeImageContentCode ;
NSMutableArray *SelfiThemePhysicalFileName ;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
// load data for collection view
SelfiThemeImage = [[NSMutableArray alloc] init];
SelfiThemeImageContentCode=[[NSMutableArray alloc] init];
SelfiThemePhysicalFileName = [[NSMutableArray alloc] init];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section
{
if (view.tag == 1) {
return 20;//SelfiThemeIm;age.count
} else {
return 15;
}
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if (cv.tag == 0) {
TopCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"TopCell" forIndexPath:indexPath];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager GET:@"http://wap.shabox.mobi/sticker_app_server/category.aspx?catid=3F7299D6-4183-4467-8ADE-41ACC3D8AC15" parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) {
NSLog(@"JSON: %@", responseObject);
NSString *array= [responseObject objectForKey:@"stickers"];
self.selfidata = array;
// NSLog(@"JSON responce Selfi: %@", self.selfidata);
for(int i=0; i<=self.selfidata.count-1; i++){
NSString *imageSelfi= [[self.selfidata objectAtIndex:i]objectForKey:@"PreviewUrlSelfie"];
NSString *CategoryCode= [[self.selfidata objectAtIndex:i]objectForKey:@"CategoryCode"];
// [SelfiThemeImage addObject: [[self.selfidata objectAtIndex:i]objectForKey:@"PreviewUrlSelfie"]];
[SelfiThemeImage addObject:[NSString stringWithFormat:imageSelfi]];
[SelfiThemeImageContentCode addObject:[NSString stringWithFormat:CategoryCode]];
}
NSLog(@"SelfiThemeImage Array - %@", SelfiThemeImage);
NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: SelfiThemeImage[indexPath.row]]];
cell.imageView.image = [UIImage imageWithData: imageData];
} failure:^(NSURLSessionTask *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
//cell.imageView.image = [UIImage imageNamed:[[NSString stringWithFormat:@"female%d",indexPath.row]stringByAppendingString:@".png"]];
return cell;
} else {
BottomCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"BottomCell" forIndexPath:indexPath];
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager GET:@"http://wap.shabox.mobi/sticker_app_server/content.aspx?catid=41BF8C14-D90D-4AFD-BEBD-44640C4EE0EB" parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) {
NSLog(@"JSON: %@", responseObject);
NSString *array= [responseObject objectForKey:@"stickers"];
self.selfidata = array;
// NSLog(@"JSON responce Selfi: %@", self.selfidata);
for(int i=0; i<=self.selfidata.count-1; i++){
// NSString *PhysicalFileName1 = [[self.selfidata objectAtIndex:i]objectForKey:@"PhysicalFileName"];
// NSString *format=@".png";
NSString *PhysicalFileName = @"http://wap.shabox.mobi/CMS/content/graphics/Stickers/D200x200/";
PhysicalFileName =[PhysicalFileName stringByAppendingString:[[self.selfidata objectAtIndex:i]objectForKey:@"PhysicalFileName"]];
PhysicalFileName =[PhysicalFileName stringByAppendingString:@".png"];
// [SelfiThemeImage addObject: [[self.selfidata objectAtIndex:i]objectForKey:@"PreviewUrlSelfie"]];
[SelfiThemePhysicalFileName addObject:[NSString stringWithFormat:PhysicalFileName]];
NSLog(@"PhysicalFileName Array - %@", PhysicalFileName);
}
NSLog(@"SelfiThemePhysicalFileName Array - %@", SelfiThemePhysicalFileName);
NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: SelfiThemePhysicalFileName[indexPath.row]]];
cell.imageView.image = [UIImage imageWithData: imageData];
} failure:^(NSURLSessionTask *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
// cell.imageView.image = [UIImage imageNamed:[[NSString stringWithFormat:@"female%d",indexPath.row]stringByAppendingString:@".png"]];
//NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: SelfiThemeImage[indexPath.row]]];
// cell.imageView.image = [UIImage imageWithData: imageData];
return cell;
}
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
NSString *ThemeURL;
BottomCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"BottomCell" forIndexPath:indexPath];
if (collectionView.tag == 0) {
NSLog(@"SelfiThemeImage imageSelfi onclick %@", [SelfiThemeImage objectAtIndex:indexPath.row]);
NSLog(@"SelfiThemeImageContentCode imageSelfi onclick %@", [SelfiThemeImageContentCode objectAtIndex:indexPath.row]);
ThemeURL = @"http://wap.shabox.mobi/sticker_app_server/content.aspx?catid=";
ThemeURL =[ThemeURL stringByAppendingString:[SelfiThemeImageContentCode objectAtIndex:indexPath.row]];
NSLog(@"SelfiThemeImageContentCode imageSelfi onclick %@", ThemeURL);
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager GET:@"http://wap.shabox.mobi/sticker_app_server/content.aspx?catid=41BF8C14-D90D-4AFD-BEBD-44640C4EE0EB" parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) {
NSLog(@"JSON: %@", responseObject);
NSString *array= [responseObject objectForKey:@"stickers"];
self.selfidata = array;
// NSLog(@"JSON responce Selfi: %@", self.selfidata);
for(int i=0; i<=self.selfidata.count-1; i++){
// NSString *PhysicalFileName1 = [[self.selfidata objectAtIndex:i]objectForKey:@"PhysicalFileName"];
// NSString *format=@".png";
NSString *PhysicalFileName = @"http://wap.shabox.mobi/CMS/content/graphics/Stickers/D200x200/";
PhysicalFileName =[PhysicalFileName stringByAppendingString:[[self.selfidata objectAtIndex:i]objectForKey:@"PhysicalFileName"]];
PhysicalFileName =[PhysicalFileName stringByAppendingString:@".png"];
// [SelfiThemeImage addObject: [[self.selfidata objectAtIndex:i]objectForKey:@"PreviewUrlSelfie"]];
[SelfiThemePhysicalFileName addObject:[NSString stringWithFormat:PhysicalFileName]];
NSLog(@"PhysicalFileName Array - %@", PhysicalFileName);
}
NSLog(@"SelfiThemePhysicalFileName Array - %@", SelfiThemePhysicalFileName);
NSData * imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: SelfiThemePhysicalFileName[indexPath.row]]];
cell.imageView.image = [UIImage imageWithData: imageData];
} failure:^(NSURLSessionTask *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}else{
NSLog(@"SelfiThemeImage imageSelfi onclick1 %@", [SelfiThemePhysicalFileName objectAtIndex:indexPath.row]);
}
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment