2016-09-20 54 views
-2

我拍照並在收藏視圖的滾動部分中顯示它們。我想顯示數字,如果該集合視圖具有一個圖像,我想顯示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

注:必須使用自定義集合視圖單元格。

  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 


} 
相關問題