我创建了一个自定义xib,我的目标是在集合视图中将其显示为如下图所示:
我设置了我的集合视图:
收藏查看标题
Sub main()
.
.
.
Dim origFileList as Collection
dirfilename = Dir(strfilename & "\")
While dirfilename <> ""
origFileList.add(dirfilename)
dirfilename=Dir()
End While
'Make a backup of all the .msg files
MkDir(strfilename & "\backUP")
FileCopy(strfilename & "\*.msg", strfilename & "\backUP\.")
'Do the loop for all files in a folder
For Each dirfilename in origFileList
If InStr(1, dirfilename, ".xls", vbBinaryCompare) > 0 Then
update_Excel_files strfilename, dirfilename, mistakes_table_name, counter
ElseIf InStr(1, dirfilename, ".msg", vbBinaryCompare) > 0 Then
update_Emails strfilename, dirfilename, mistakes_table_name, counter
End If
dirfilename = Dir
Next dirfilename
.
.
'MAKE SURE YOU CLEAN UP AT THE END OF MAIN SUB
Kill(strfilename & "\backUP\*.*")
RmDir(strfilename & "\backUP")
End Sub
Sub update_Emails(strfilename As String, dirfilename As String, mistakes_table_name As String, counter As Integer)
.
'HERE YOU CAN USE DIR as NOW IT WILL NOT INTERFERE WITH Dir State in main
.
'PROCESS ON .MSG FILES FROM <<strfilename & "\backUP">>
.
.
.
End Sub
数据来源
+(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];
这就是我得到的:
正如你所看到的那样,只有一个项目,但我的数组中有多个项目,对于我在这里做错了什么的任何建议都会非常感激,因为我坚持这个。
Video.Content [] Youtube []:
[type]:视频 [内容] :( “\ n [youtube] :( \ n 4Cw856cbyNI,\ n GcmEqI9fpYo,\ n L7xR42O825Q,\ n kZem01RQOeQ,\ n
L7xR42O825Q,\ n \“swgU9Q-8aEA \”,\ n \“v_joMRl6wus \”,\ n
tKwSgFo0Dz8,\ n \“Rg2C-9QJmN0 \”,\ n \“UEW3EYc_aKE \”\ n
)\ n“)
视频类:
[self.collectionViewDataSourceArray addObject:dataSource];
视频类
@interface Videos : JSONModel
@property (strong, nonatomic) NSString *title;
@property (strong, nonatomic) NSString *type;
@property (strong, nonatomic) NSString *display;
@property (strong, nonatomic) NSArray <Video> *content;
注意:我已经查看过:Link 1,但在我的情况下它没用。
答案 0 :(得分:0)
1.let cellReuseIdentifier:String =“cellName”。
2. @ IBOutlet weak var myCollectionView:UICollectionView?
3.var nibName = UINib(nibName:cellReuseIdentifier,bundle:nil) myCollectionView?.register(nibName,forCellWithReuseIdentifier:cellReuseIdentifier)
4.let cell = collectionView.dequeueReusableCell(withReuseIdentifier:cellReuseIdentifier,for:indexPath as IndexPath)as! MyCollectionViewCell