我想要做的是,当没有UILabel
时,我正在向UITextView
帧和image
向上移动。
当我在本地做这件事时,它工作正常。但是现在当图像从服务器下载时,当我检查nil
图像时,它给了我错误的输出。
我正在尝试水平滚动
这是我试过的代码
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *myCell=nil;
myCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell"
forIndexPath:indexPath];
UIImageView *ImageView=(UIImageView*)[myCell viewWithTag:9];
UILabel *questionLabel=(UILabel*)[myCell viewWithTag:567];
UITextView *answerTextView=(UITextView*)[myCell viewWithTag:6];
questionLabel.text=[_questionsArray objectAtIndex:indexPath.row];
answerTextView.text=[_answerArray objectAtIndex:indexPath.row];
[ImageView setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http:/%@",[[_arrayOfDictionary objectAtIndex:indexPath.row] objectForKey:@"image"]]] ];
if (ImageView.image==nil) {
//Always Satisfying this condition
//Set Frame
return myCell;
}else{
return myCell;
}
}
请向我提供解决方案。以及为什么每次都满足if
声明的原因。
(未选中Autolayout )
答案 0 :(得分:0)
添加AFNetworking以实现图像视图更新的异步解决方案,如
if (userBasicInfo.userImage == nil) {
__weak LGMessageBoxCell *weakCell = cell;
[cell.userImage setImageWithURLRequest:[[NSURLRequest alloc] initWithURL:[NSURL URLWithString:userBasicInfo.imageUrl]]
placeholderImage:[UIImage imageNamed:@"facebook-no-user.png"]
success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image){
weakCell.userImage.image = image;
[weakCell setNeedsLayout];
// reload your tableView current cell here
}
failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error){
}];
}