如何获取数组索引值并在集合视图的标签中显示它们
How to get the Array Index Value and showing them in label in collection view
我拍照并在集合中的滚动部分显示它们 view.i 想显示数字,如果集合视图有一张图片,我想显示 1.if 有 3 张三张图片我需要为相应的图像显示 3,2,1。因为我首先添加的是最新的图片。编号应该是降序的。请帮我做这个。
我做的是..
NSUInteger index;
for (id item in self.myimagearray)
{
index = [[self.myimagearray indexOfObject:self.myimagearray];
NSLog(@" the index are:%lu",(unsigned long)index);
Cell.waterMark_lbl.text = [NSString stringWithFormat:@"%lu",(unsigned long)index];
}
它在所有图像中显示的计数都像 3。请帮我做这个 ..
注意:您必须使用自定义集合视图单元格。
- 用
label
和 image view
创建一个 custom collection view cell
。
- 然后创建
IBOutlet
到 custom collection view cell class
,.h
文件。
- 然后调用
collection view delegate methods.
,如下所示。
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [self.yourarray count];
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
MyCutomCollectionViewCell *thecell = [collectionView dequeueReusableCellWithReuseIdentifier:@"your_cell_identifier" forIndexPath:indexPath];
//this is how you can get the index path to string
NSString *the_index_path = [NSString stringWithFormat:@"%li", (long)indexPath.row];
//then bind it to your label
thecell.mylabel.text = the_index_path;
//and bind your image data here
}
我拍照并在集合中的滚动部分显示它们 view.i 想显示数字,如果集合视图有一张图片,我想显示 1.if 有 3 张三张图片我需要为相应的图像显示 3,2,1。因为我首先添加的是最新的图片。编号应该是降序的。请帮我做这个。 我做的是..
NSUInteger index;
for (id item in self.myimagearray)
{
index = [[self.myimagearray indexOfObject:self.myimagearray];
NSLog(@" the index are:%lu",(unsigned long)index);
Cell.waterMark_lbl.text = [NSString stringWithFormat:@"%lu",(unsigned long)index];
}
它在所有图像中显示的计数都像 3。请帮我做这个 ..
注意:您必须使用自定义集合视图单元格。
- 用
label
和image view
创建一个custom collection view cell
。 - 然后创建
IBOutlet
到custom collection view cell class
,.h
文件。 - 然后调用
collection view delegate methods.
,如下所示。
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { return 1; } -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { return [self.yourarray count]; } -(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { MyCutomCollectionViewCell *thecell = [collectionView dequeueReusableCellWithReuseIdentifier:@"your_cell_identifier" forIndexPath:indexPath]; //this is how you can get the index path to string NSString *the_index_path = [NSString stringWithFormat:@"%li", (long)indexPath.row]; //then bind it to your label thecell.mylabel.text = the_index_path; //and bind your image data here }