2017-09-14 111 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

相关问题