2015-01-24 15 views
0

동일한 콘텐츠를로드하는 UITableView 및 UICollectionView가 있지만 프로토콜 메서드가 거의 동일하게 정의되어 있어도 컬렉션 뷰에서 빈 뷰를 제공하지만 테이블 뷰는 표시합니다 함유량. 내가 -imageWithData에서 다시 이미지를 얻을 사전이 사전은 CollectionView 셀의 UIImageView IBOutlet 속성로드되지 않음

  • 에 저장

    1. :이 질문의 맥락을 이해 그래서, 나는 두보기에 내용을로드하기 전에 어떤 일이 일어나는지 다룰 것입니다 다음과 같은 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의 대리자

  • +0

    두 가지 질문 : \ na)'- (NSInteger) collectionView : (UICollectionView *) collectionView numberOfItemsInSection : (NSInteger) 섹션 {'셀 수를 설정 하시겠습니까? \ nb)'[UIImage '[UIImage alloc] initWithCIImage : self.streamItems [indexPath.row] [@ "ThumbnailPhoto"]];'대신에 image.Images [self.streamImages [indexPath.row] – GlennRay

    +0

    @GlennRay 예, -numberOfItemsInSection : [self.streamItems count]를 반환합니다. 난 그냥 사용하여 시도 - imageNamed : 당신이 말했듯이 런타임 오류 : NSInvalidArgumentException, 이유 : [NSDictionaryM stringByDeletingPathExtension] : 인식 할 수없는 선택기 인스턴스로 보낸 ... ??? – 17nisa

    +0

    어떻습니까? [UIImage imageNamed : self.streamImages [indexPath.row] [@ "ThumbnailPhoto"]]'? – GlennRay

    답변

    0

    CellViewController 후 셀 * = [collectionView dequeueReusableCellWithReuseIdentifier : 식별자 forIndexPath : indexPath];

    if (cell == nil) cell = [[CellViewController alloc] init];

    +0

    나는 그것을 시도했지만 아무것도 변경되지 않았다. 뷰는 비어 있습니다. 이것은 셀 클래스를 추가하는 방식과 관련이 있습니다. 그것은 tableViewCell 이미지 속성과 함께 작동하지만 CellViewController 클래스에서 생성 된 사용자 정의 IBOutlet imageView 속성을 가진 내 collectionView에서는 작동하지 않습니다. – 17nisa

    +0

    또한 문제가 이미지 자체에 있는지 또는 IBOutlet 속성 'imageOfCell을 참조 하는지를 확인하기 위해 UILabel 유형의 IBOutlet을 추가하려고했습니다.'나는 운이 없었으므로 셀의 UIImageView 콘센트를 참조하는 방법에 문제가 있다고 짐작하고있다. – 17nisa

    +0

    사전에서 이미지에 액세스하는 방법에 문제가있을 수 있으며 initWithCIImage 메서드를 사용하지 마십시오. 테이블 뷰 대리자. CIImage는 핵심 이미지이므로 처음에는 사전에 저장하지 않았다고 생각합니다. – Gunjit