如何获取数组索引值并在集合视图中的标签中显示它们

问题描述:

我拍照并在收藏视图的滚动部分中显示它们。我想显示数字,如果该集合视图具有一个图像,我想显示1.如果有三个三个图像,那么我需要为相应的图像显示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计数。请帮我做..

+0

你不应该快列举并设置单元格文本。你应该使用委托方法indexpath.row来循环数组。 –

+0

你可以给样品@ Teja Nandamuri – kavi

+0

你想显示你的图像的图像编号,如果它是你需要的,你可以在'委托方法 –

注:必须使用自定义集合视图单元格。

  1. 创建custom collection view cell一个label和一个image view
  2. 然后创建IBOutlet s到custom collection view cell class,.h文件。
  3. 然后像下面那样呼叫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 


}