林有問題的設置圖像到UiCollectionViewCell加載圖像到UICollectionVIewCell
這是我的代碼:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
NSURL * imageURL = [NSURL URLWithString:@"https://mozorg.cdn.mozilla.net/media/img/firefox/firstrun/logo.png?2013-06"];
NSData * imageData = [NSData dataWithContentsOfURL:imageURL];
UIImage * image = [UIImage imageWithData:imageData];
UIImageView * myImageView = [[UIImageView alloc] initWithImage:image];
myImageView.image = [UIImage imageNamed:@"myimg"];//set the image
GLCell *cell = (GLCell *)[collectionView dequeueReusableCellWithReuseIdentifier:CELL_IDENTIFIER forIndexPath:indexPath];
cell.displayString = [NSString stringWithFormat:@"%d user number", indexPath.row];
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"myimg"]];
return cell;
}
字符串值顯示沒有問題,但電池沒有圖像。
你確定你的圖像文件不具有擴展名?可能是它應該改爲'myImageView.image = [UIImage imageNamed:@「myimg.JPEG」]'例如? – Avt
不設置myImageView.image它是覆蓋值 – codercat
您的imageview不添加tableview單元格的子視圖 – codercat