【发布时间】:2015-02-23 18:39:52
【问题描述】:
@implementation StudyViewController
- (void)viewDidLoad {
[super viewDidLoad];
//[super viewWillAppear:animated];
... 基本上我通过afnetworking接收响应对象。 然后将数据存储在一个名为 arData 的全局定义的 nsmutable 数组中
............
...........
[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];
然后将 nsmutable 对象索引存储为字典,以便在创建图像路径时访问。 我需要从这个 nsmutable 数组中提取 3 组数据(firstUID、第二个、第三个),这些数据将被传递给 NSURL 以构造图像 url 路径,如下所示。 其余参数(hyperText、UrlKey、portNumber、分隔符)通过 nsdictionary(此处未显示)传递。
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- 我似乎无法在控制台内部获得任何 NSLOG 输出
-(UICollectionView *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
2- 即使我知道从 Web 服务接收到的参数是正确的,我也无法显示任何图像(并且当 viewdidload 时,我可以 NSLOG 它们而不会出现任何问题。
任何帮助将不胜感激。
谢谢。
【问题讨论】:
-
检查您的共享控制器是否存在?
-
arrData nsmutable 在 Global.h 中定义&它存在于这个视图控制器StudyViewController 中
标签: ios objective-c uicollectionview