@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、second、third),这些数据将传递给 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。
如有任何帮助,我们将不胜感激。
谢谢。
最佳答案
您应该首先看到对 numberOfItemsInSection
的调用。如果您可以在那里(或 NSLog)设置断点并且 [[[Global sharedGlobal]arrData] count]
的查看计数不大于 0,那么这可能有助于解决问题。如果它没有触发该委托(delegate)回调,则可能是委托(delegate)没有为 Collection View 正确设置。
关于ios - 无法在 uicollectionview 中显示 uimage 集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28680953/