ios - Replacing Occurrences of Strings in NSMutableArray Only Working Once -
i confounded, , perhaps have missed simple, can't find it.
i'll problem in theoretical, because have done test , still cannot work stripped down code. using spritebuilder, shouldn't causing issue - can log value getting in text input, cannot value array second time - enough ranting, time code.
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]; }
content.h
@property nsarray *base; @property nsarray *changearray;
content.m
-(void)somefunction{ _base = @[@"this one",@"this two",@"this 2 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]; } }]; }
replaceme.h
@property cctextfield *changethetext; -(void)_changethetextselector;
replaceme.m
-(void)_changethetextselector{ self.visible=no; }
when call mainscene's somefuction
, set works dandy first time - , first time. can't changearray
update after first time run enumeration.
i know changethetext
changing, logs out, when log changearray[idx]
, stuck @ first changethetext
.
any ideas?
try , compare code. working fine me;
nsarray* base = @[@"this one",@"this two",@"this 2 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);
Comments
Post a Comment