2017-09-14 108 views
0

我創建了一個自定義的廈門國際銀行和我的目標是低於集合視圖中,如圖像顯示出來:UICollectionView沒有返回所有的細胞

enter image description here

設置我的收藏看法是這樣的:

集合視圖名稱

+(id)newTitleView 
{ 
VideoCollectionViewTitleView* vidcollectionTitleView = [[[NSBundle mainBundle] loadNibNamed:@"ProductCollectionViewTitleView" owner:nil options:nil] lastObject]; 

if ([vidcollectionTitleView isKindOfClass:[VideoCollectionViewTitleView class]]) 
{ 
    return vidcollectionTitleView; 
} 
else 
{ 
    return nil; 
} 
} 

數據源

-(instancetype)initWithVideos:(Videos *)videos 
    { 
    self = [super init]; 
    if (self) 
    { 
    _videos = videos; 
    } 
return self; 
} 

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section 
{ 

return _videos.content.count ; 

} 


-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 
{ 

Video *video = [self.videos content][indexPath.row]; 
VideoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kGENERIC_COLLECTION_CELL_ID forIndexPath:indexPath]; 


for (int cnt = 0; cnt <[[video youtube]count]; cnt++) { 

    NSMutableString *youtubeImageString = [[NSMutableString alloc]initWithString:kYOUTUBE_IMAGE_URL]; 

    [youtubeImageString replaceOccurrencesOfString:@"videoId" withString: [video youtube][cnt++] options:0 range:NSMakeRange(0, youtubeImageString.length-1)]; 
    NSLog(@"check the url %@", youtubeImageString); 

    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:youtubeImageString] 
         placeholderImage:nil 
          completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 
           if (cacheType != SDImageCacheTypeMemory) 
           { 
            cell.imageView.alpha = 0.0; 
            double val = ((double)arc4random()/ARC4RANDOM_MAX)*0.8; 
            [UIView animateWithDuration:0.2 delay:val options:UIViewAnimationOptionCurveEaseInOut animations:^{ 
             cell.imageView.alpha = 1.0; 
            } completion:nil]; 
           } 

          }]; 

    //set labels 

    [cell.nameLabel setText:@"Videoooos"]; 

} 

return cell; 
} 

這是我的對象添加到數據源:

VideoCollectionViewTitleViewDataSource *dataSource = [[VideoCollectionViewTitleViewDataSource alloc]initWithVideos:self.model.videos]; 
     [self.collectionViewDataSourceArray addObject:dataSource]; 

這是我得到的結果是:

result

當我把一個斷點:[self.collectionViewDataSourceArray addObject:dataSource];這是我得到的:

break point

正如你可以看到有唯一的項目,但也有在我的數組不止一個項目,在我做錯了什麼在這裏任何建議將非常感激,因爲我堅持這一點。

Video.Content []的Youtube []:

[類型]:視頻 [含量]:( 「\ N [YouTube的]:(\ n 4Cw856cbyNI,\ n GcmEqI9fpYo,\ ñL7xR42O825Q,\ n kZem01RQOeQ,\ n
L7xR42O825Q,\ n \ 「swgU9Q-8aEA \」,\ n \ 「v_joMRl6wus \」,\ n
tKwSgFo0Dz8,\ n \ 「Rg2C-9QJmN0 \」,\ n \ 「UEW3EYc_aKE \」\ n
)\ n「)

視頻類:

@interface Videos : JSONModel 

@property (strong, nonatomic) NSString *title; 
@property (strong, nonatomic) NSString *type; 
@property (strong, nonatomic) NSString *display; 
@property (strong, nonatomic) NSArray <Video> *content; 

視頻類

#import <Foundation/Foundation.h> 
#import "JSONModel.h" 

@protocol Video @end 
@interface Video : JSONModel 

@property (strong, nonatomic) NSArray *youtube; 

@end 

注:我已經看了看:Link 1,但它是不是在我的情況非常有用。

+0

調用'numberOfItemsInSection'時,'_videos.content.count'的值是什麼? – DonMag

+0

@DonMag「section = 0」這就是當我在那裏放置一個斷點時得到的結果 –

+0

不... ... _videos.content.count的值是多少?這是一個有效的數組嗎?或者它是一個'1'對象的數組? – DonMag

回答

0

1.let cellReuseIdentifier:String =「cellName」。

2. @ IBOutlet weak var myCollectionView:UICollectionView?

3.var nibName = UINib(nibName:cellReuseIdentifier,束:無) myCollectionView .register(nibName,forCellWithReuseIdentifier:cellReuseIdentifier)?

4.let細胞=的CollectionView。dequeueReusableCell(withReuseIdentifier:cellReuseIdentifier,用於:indexPath作爲IndexPath)as! MyCollectionViewCell

相關問題