【发布时间】:2013-11-16 00:05:21
【问题描述】:
我遇到了一个奇怪的字符串/数组问题。当我计算数组中的对象数时(使用 [字符串描述] 获取的值,它返回两个正确数量的对象。当我尝试下载图像时,UIImage 不显示任何内容。
这是来自数组 photoArg 的 URL 日志(如果您尝试使用它们,它会说它们是无效的,因为我更改了几行)
(
"\n\"https://scontent-a.xx.fbcdn.net/hphotos-ash2/s720x720/196148_2542310658202194_959795763_n.jpg\"",
"\n\"https://fbcdn-sphotos-c-a.akamaihd.net/hphotos-ak-ash3/s720x720/576808_2239914766108450_770925407_n.jpg\"\n"
)
这是我的 numberOfItemsInSection:
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [self.photoArg count];
}
我的 cellForItemAtIndexPath:
- (TBCollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"CollectionViewCell";
TBCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
NSString *ImageURL = [self.photoArg objectAtIndex:indexPath.item];
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:ImageURL]];
[cell.imageView setImage:[UIImage imageWithData:imageData]];
return cell;
}
我的 TBCollectionViewCell 只是一个标准的 UICollectionViewCell,除了里面有一个 UIImageView。
我认为 URL 不会在 cellForItemAtIndexPath: 方法中下载的原因是它们的格式不正确。如果是这样,我应该如何正确格式化数组数据?
【问题讨论】:
标签: ios uitableview nsstring nsarray