I’m generating a list from some string up to 4
NSUInteger total = MIN(4, myNSMutableArray.count);
CGFloat xPos = 0.0f;
CGFloat yPos = 450.0f;
CGFloat yPadding = 10.0f;
NSInteger count = 0;
for (ItemClass *item in myNSMutableArray) {
if (count == total) return;
CCLabelTTF *itemLabel = [CCLabelTTF labelWithString:item.name
dimensions: CGSizeMake(280, 50)
alignment:UITextAlignmentCenter
lineBreakMode:UILineBreakModeWordWrap
fontName:@"MyFont.otf"
fontSize:28.0f];
itemLabel.anchorPoint = ccp(0,0);
itemLabel.position = ccp(xPos, yPos);
itemLabel.tag = item.itemID;
[self addChild:itemLabel];
[myNSMutableArrayOfLabels addObject:itemLabel];
yPos -= itemLabel.contentSize.height + yPadding;
count++;
}
Lets stay that I have list of strings like: string 1, string 2, string 3, string 3, string 3, string 3. I want to group them in order to obtain something like:
string 1
string 2
string 3 (4)
Because your data is a NSMutableArray, it is simple enough: