#import "ViewController.h"
#import "CollectionViewCell1234.h"
#import "ViewController6778.h"
@interface ViewController ()<NSURLConnectionDelegate,NSURLConnectionDataDelegate,UICollectionViewDelegate,UICollectionViewDataSource,UINavigationControllerDelegate>
@property (nonatomic ,strong)NSData *resultdata;
@property ( nonatomic,strong)NSMutableArray *array1;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self webserviceCallingUsingGETMethod];
_collectionview.backgroundColor = [UIColor purpleColor];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark- delegate
-(void)webserviceCallingUsingGETMethod
{
NSString *stringurl = @"https://itunes.apple.com/search?";
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",stringurl]];
NSString *params = @"term=jack+johnson&entity=musicVideo";
NSData *postdata = [params dataUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]init];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:postdata];
[NSURLConnection connectionWithRequest:request delegate:self];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
if (connectionError) {
NSLog(@"Error :%@", connectionError.localizedDescription);
return;
}
if (data) {
self.resultdata = data;
NSError *error = nil;
NSDictionary *result = [NSJSONSerialization JSONObjectWithData:_resultdata options:NSJSONReadingAllowFragments error:&error];
NSLog(@"RESULT :%@", result);
NSArray *array = [result valueForKey:@"results"];
_array1 =[[NSMutableArray alloc]init];
_array1 = [NSMutableArray arrayWithArray:array];
NSLog(@"122345%@",array);
dispatch_async(dispatch_get_main_queue(), ^{
[_collectionview reloadData];
});
}
}];
}
#pragma mark-collectionview delegate
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return _array1.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
NSString *nschool = @"sri";
CollectionViewCell1234 *cell = [collectionView dequeueReusableCellWithReuseIdentifier:nschool forIndexPath:indexPath];
cell.imgview.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",[[_array1 valueForKey:@"artworkUrl30"]objectAtIndex:indexPath.row]]]]];
cell.backgroundColor = [UIColor greenColor];
cell.lbl1.text = [[self.array1 valueForKey:@"wrapperType"]objectAtIndex:indexPath.row];
cell.lbl2.text = [[self.array1 valueForKey:@"artistName"]objectAtIndex:indexPath.row];
cell.lbl3.text = [[self.array1 valueForKey:@"releaseDate"]objectAtIndex:indexPath.row];
cell.lbl4.text = [[self.array1 valueForKey:@"country"]objectAtIndex:indexPath.row];
cell.lbl5.text = [[self.array1 valueForKey:@"currency"]objectAtIndex:indexPath.row];
cell.lbl6.text = [[self.array1 valueForKey:@"trackName"]objectAtIndex:indexPath.row];
cell.lbl7.text = [[self.array1 valueForKey:@"kind"]objectAtIndex:indexPath.row];
NSInteger artid= [[[self.array1 valueForKey:@"artistId"]objectAtIndex:indexPath.row]integerValue];
NSString *str1 =[NSString stringWithFormat:@"%ld",(long)artid];
cell.lbl8.text = str1;
CGFloat cp = [[[self.array1 valueForKey:@"collectionPrice"]objectAtIndex:indexPath.row]floatValue];
NSString *str4 = [NSString stringWithFormat:@"%3f",cp];
cell.lbl9.text = str4;
cell.lbl10.text = [[self.array1 valueForKey:@"collectionExplicitness"]objectAtIndex:indexPath.row];
cell.lbl11.text = [[self.array1 valueForKey:@"primaryGenreName"]objectAtIndex:indexPath.row];
NSInteger tracknum = [[[self.array1 valueForKey:@"trackId"]objectAtIndex:indexPath.row]integerValue];
NSString *str3 = [NSString stringWithFormat:@"%ld",(long)tracknum];
cell.lbl12.text = str3;
cell.lbl13.text = [[self.array1 valueForKey:@"trackExplicitness"]objectAtIndex:indexPath.row];
NSInteger tracknum1 =[[[self.array1 valueForKey:@"trackTimeMillis"]objectAtIndex:indexPath.row]integerValue];
NSString *str2 = [NSString stringWithFormat:@"%ld",(long)tracknum1];
cell.lbl14.text =str2;
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:@"segue" sender:self];
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([[segue identifier] isEqualToString:@"segue"])
{
ViewController6778 *vc2 = [segue destinationViewController];
vc2.img1.images ;
}
}
@end