我正在加载项目列表
NSMutableArray *listOfItems;
Items *items = [ItemParser loadItemsForALevel:selectedLevel fromASuperLevel:selectedSuperLevel];
在我的for循环中,我添加到NSMutableArray以便将其显示到我的菜单层
for (Item *item in items.items) {
//Initialing a CCMenuItem and calling a removeMethod
CMenuItem *anItem = [[CCMenuItemSprite itemFromNormalSprite:[CCSprite spriteWithFile:item.picture]
selectedSprite:[CCSprite spriteWithFile:item.picture]
target:self
selector:@selector(removeMethod:)] retain];
NSString *textToDisplay;
textToDisplay = item.ItemText;
[listOfItems addObject:textToDisplay];
}
-(void)removeMethod:(id)sender {
CCMenuItemSprite *pointedItem = (CCMenuItemSprite *)sender;
//Now I'm removing only from the layer
[CCCallFunc actionWithTarget:pointedItem selector:@selector(removeFromParentAndCleanup:)]
//How do I remove it from array?
}
如何从listOfItems数组中删除所选项并更新它?
答案 0 :(得分:0)
将'textToDisplay'设为全局变量..在removeMethod中。您可以使用
将其从数组中删除[listOfItems removeObjectAtIndex:[listOfItems indexOfObject:textToDisplay]];
希望这个有用: - )