Reputation: 4402
@implementation StudyViewController
- (void)viewDidLoad {
[super viewDidLoad];
//[super viewWillAppear:animated];
... Basically I receive the responseobject via afnetworking. Then store the data in a globally defined nsmutable array called arData
............
...........
[manager POST:studysearchUrl parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
[MBProgressHUD hideHUDForView:self.view animated:YES];
NSLog(@"%@",responseObject);
[Global sharedGlobal].arrData = responseObject;
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[MBProgressHUD hideHUDForView:self.view animated:YES];
NSLog(@"Error: %@", error);
}];
}
#pragma collection view methods
- (NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
-(NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [[[Global sharedGlobal]arrData] count];
}
-(UICollectionView *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"StudyCell" forIndexPath:indexPath];
Then the nsmutable object indexes are stored as dictionary to be accessed while creating the image path. I needed to extract 3 sets of data(firstUID, second, third) from this nsmutable array which will be passed on to NSURL to construct the image url path as shown below. The rest of the parameters (hyperText, UrlKey, portNumber, seperator) are passed via nsdictionary(not shown here).
UIImageView *img = (UIImageView *)[cell viewWithTag:1000];
NSDictionary *dictionary = [Global sharedGlobal].arrData[indexPath.row];
img.imageURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@%@%@?parametersintheWebServer&firstID=%@&secondID=%@&thirdID=%@",hyperText, UrlKey, portNumber, seperator, [Global sharedGlobal].arrData[indexPath.row] [@"firstUID"],[Global sharedGlobal].arrData[indexPath.row][@"secondUID"],[Global sharedGlobal].arrData[indexPath.row][@"thirdUID"]]];
return cell;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
1- I cannot seem to get the NSLOG output anything in the console inside
-(UICollectionView *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
2- I cannot display any image even though I know the parameters received from the web service is correct (& I can NSLOG them without any issue when the viewdidload.
Any help would be appreciated.
Thank you.
Upvotes: 0
Views: 64
Reputation: 1536
You should first be seeing calls to numberOfItemsInSection
. If you can set a breakpoint in there (or NSLog) and the see count for [[[Global sharedGlobal]arrData] count]
is not greater than 0 then this may help trouble shoot. If it's not hitting that delegate call back maybe the delegates are not set up correctly for the collectionview.
Upvotes: 1