Ios 替换NSMutableArray中出现的字符串只工作一次

Ios 替换NSMutableArray中出现的字符串只工作一次,ios,objective-c,string,enumeration,spritebuilder,Ios,Objective C,String,Enumeration,Spritebuilder,我很困惑,也许错过了一些简单的东西,但我找不到 我将从理论上解决这个问题,因为我已经做了一个测试,但仍然无法使用精简的代码。我使用的是SpriteBuilder,但这不应该是问题的根源——我可以将我在文本输入中获得的值记录下来,但无法再次将该值输入到数组中——但这已经足够了,需要一些代码 Main.h #import "Content.h" #import "ReplaceMe.h" @property Content *contentInstance; @property ReplaceMe

我很困惑,也许错过了一些简单的东西,但我找不到

我将从理论上解决这个问题,因为我已经做了一个测试,但仍然无法使用精简的代码。我使用的是SpriteBuilder,但这不应该是问题的根源——我可以将我在文本输入中获得的值记录下来,但无法再次将该值输入到数组中——但这已经足够了,需要一些代码

Main.h

#import "Content.h"
#import "ReplaceMe.h"

@property Content *contentInstance;
@property ReplaceMe *replaceMeInstance; 
Main.m

   -(void)someFunction{
    _contentInstance = (Content*)[CCBReader load:@"ContentScene"];
  [_contentInstance.changeArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        if ([_contentInstance.base[idx] containsString:@"one"]){
            NSLog(@"I contain one!");
            NSString *replace = [_content.testArray[idx] stringByReplacingOccurrencesOfString:@"one" withString:changeTheText.string];
            [_content.testArray replaceObjectAtIndex:idx withObject:replace];
            NSLog(@"%@",_content.testArray[idx]);
        }
    }];
[_contentInstance updateLabels];
    }
内容.h

@property NSArray *base;
@property NSArray *changeArray;
内容

-(void)someFunction{
    _base = @[@"This is one",@"This is two",@"This is two point one"];
    _changeArray = [base mutableCopy];
}
-(void)updateLabels{
    [_changeArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
        _labeler = [CCLabelTTF labelWithString:[NSString stringWithFormat:@"%@",_changeArray[idx]] fontName:@"Helvetica" fontSize:12.0f];
        }
    }];
}
代替我

@property CCTextField *changeTheText;
-(void)_changeTheTextSelector;
代替我

-(void)_changeTheTextSelector{
self.visible=NO;
}
当我调用MainScene的
someFunction
时,这个设置在第一次——也是第一次——就可以正常工作。第一次运行枚举后,我无法更新
changeArray

我知道
changetext
在注销时正在更改,但当我登录
changeArray[idx]
时,它在第一个
changetext
时被卡住了


有什么想法吗?

试试这个,并与您的代码进行比较。这对我来说很好

NSArray* base = @[@"This is one",@"This is two",@"This is two point one"];
NSMutableArray *changeArray = [base mutableCopy];

[base enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
    if ([obj containsString:@"one"]) {
        NSLog(@"data : %@", changeArray[idx]);
        //--
        [changeArray replaceObjectAtIndex:idx withObject:[((NSString*) obj) stringByReplacingOccurrencesOfString:@"one" withString:@""]];
    }
}];

NSLog(@"changeArray %@", changeArray);

你为什么不试试以前熟悉的for循环进行枚举,然后告诉我结果呢?Shoaib,现在很有魅力。你的代码是100%正确的。谢谢