동일한 콘텐츠를로드하는 UITableView 및 UICollectionView가 있지만 프로토콜 메서드가 거의 동일하게 정의되어 있어도 컬렉션 뷰에서 빈 뷰를 제공하지만 테이블 뷰는 표시합니다 함유량. 내가 -imageWithData에서 다시 이미지를 얻을 사전이 사전은 CollectionView 셀의 UIImageView IBOutlet 속성로드되지 않음
에 저장
- :이 질문의 맥락을 이해 그래서, 나는 두보기에 내용을로드하기 전에 어떤 일이 일어나는지 다룰 것입니다 다음과 같은 TableViewController 클래스뿐만 아니라 CollectionViewController 클래스에 의해 액세스 및 구현 :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { // Configure the cell... UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"User ID" forIndexPath:indexPath]; //setting UI NSString *milesFrom = self.streamItems[indexPath.row][@"MilesAway"]; cell.textLabel.text = [NSString stringWithFormat:@"%@, Distance Away: %@", self.streamItems[indexPath.row][@"UserName"], milesFrom]; UIImage *photo = [[UIImage alloc]init]; photo = self.streamItems[indexPath.row][@"ThumbnailPhoto"]; cell.imageView.image = photo; return cell; }
이 부분은 내가 그것을해야하지만 컬렉션보기하지 않는 것처럼 작동합니다
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { static NSString *identifier = @"MyCell"; CellViewController *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; UIImage *imageReturned = [[UIImage alloc]initWithCIImage: self.streamItems[indexPath.row][@"ThumbnailPhoto"]]; cell.imageOfCell.image = imageReturned; [cell.imageOfCell sizeToFit]; return cell; }
이 CellViewController 클래스에는 IBOutlet 'imageOfCell'속성이 있습니다. 이 속성은 내 콜렉션 뷰 안에있는 셀 ("MyCell")의 맨 위에 드래그 한 이미지 뷰 객체를 참조합니다. 컬렉션 뷰는 말했듯이 내용이없는 빈 뷰를 제공합니다. 디버깅에서 '사진'인스턴스와 'ImageReturned'인스턴스가 모두 똑같은 값을 가짐을 알았습니다. 이러한 이유로 컬렉션 뷰가 이미지를로드하지 않지만 테이블 뷰는 왜 그렇게되는지 알 수 없습니다. 경우에는 그것이 내가 컬렉션보기를로드하는 방식과는 아무 상관이있다, 내 -viewDidLoad 방법 정의 포함했다 :
@implementation StreamCollectionViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
[self.collectionView registerClass: [CellViewController class]forCellWithReuseIdentifier:@"MyCell"];
UICollectionViewFlowLayout *flow = [[UICollectionViewFlowLayout alloc]init];
[flow setScrollDirection:UICollectionViewScrollDirectionVertical];
[self.collectionView setCollectionViewLayout:flow];
//create object to deal with network requests
StreamController *networkRequester = [[StreamController alloc]init];
[networkRequester getFeedWithCompletion:^(NSMutableArray *items, NSError *error) {
if (!error) {
self.streamItems = items;
[self.collectionView reloadData];
}
else{
NSLog(@"Error getting streamItems: %@", error);
}
}];
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = NO;
// Register cell classes
// [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
// Do any additional setup after loading the view.
}
을 나는 만약 내가 놀라지 않을 것이다 컬렉션 뷰를 사용하여 상당히 새로운 오전 내가 누락 된 비교적 작은 것. 미리 감사드립니다! uicollectionView의 cellforrowatindexpath의 대리자
두 가지 질문 : \ na)'- (NSInteger) collectionView : (UICollectionView *) collectionView numberOfItemsInSection : (NSInteger) 섹션 {'셀 수를 설정 하시겠습니까? \ nb)'[UIImage '[UIImage alloc] initWithCIImage : self.streamItems [indexPath.row] [@ "ThumbnailPhoto"]];'대신에 image.Images [self.streamImages [indexPath.row] – GlennRay
@GlennRay 예, -numberOfItemsInSection : [self.streamItems count]를 반환합니다. 난 그냥 사용하여 시도 - imageNamed : 당신이 말했듯이 런타임 오류 : NSInvalidArgumentException, 이유 : [NSDictionaryM stringByDeletingPathExtension] : 인식 할 수없는 선택기 인스턴스로 보낸 ... ??? – 17nisa
어떻습니까? [UIImage imageNamed : self.streamImages [indexPath.row] [@ "ThumbnailPhoto"]]'? – GlennRay