我想將所有cell.img.tag添加到我的nsmutable數組中。但是,我嘗試了多種方式來執行此操作,例如for循環,但每次結果都不正確。我需要將每個單獨的標記添加到NSMutableArray。我會在下面發佈我的代碼給你一個想法。注意:這只是爲了展示我在做什麼,這不是我嘗試使用的方法來完成這項工作。正確添加標記項到一個nsmutable陣列
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
Cell *cell = (Cell*)[collectionView dequeueReusableCellWithReuseIdentifier:@"Cell" forIndexPath:indexPath];
NSString *string = [addressString valueForKey:@"number"];
array = [[NSMutableArray alloc]init];
cell.img.tag = string.intValue;
[array addObject:[NSNumber numberWithInt:cell.img.tag]];
return cell;
}
編輯:當我用for循環,它會顯示所有的標籤,但剛剛結束了相同的值創建多個陣列,每個陣列重複多次,像這樣。 (1,1,1)(2,2,2)。