ios - Only last row in method execute (Objective-C) -
first want apologize lack of knowledge in programming in general. in way of learning , have discovered site huge compliment me of doing so.
i have created program 3 uitextfield(theplace,theverb,theoutput) , 2 uitextview 1 of textviews(theoutput) take text other textview(thetemplate) , replaces strings text entered in textfields.
when click button triggers method createstory listed below. works fine 1 exception. text in output changes string 'number' text in textfield. if change order in method replace 'place','number','verb' verb changed, not number.
im sure sort of easy fix can't find it. can of me troubleshooting?
- (ibaction)createstory:(id)sender { theoutput.text=[thetemplate.text stringbyreplacingoccurrencesofstring:@"<place>" withstring:theplace.text]; theoutput.text=[thetemplate.text stringbyreplacingoccurrencesofstring:@"<verb>" withstring:theverb.text]; theoutput.text=[thetemplate.text stringbyreplacingoccurrencesofstring:@"<number>" withstring:thenumber.text]; } many // emil
the problem you're overwriting contents of theoutput.text each line; var1 = var2; overwrites data in var1 , replaces contents of var2.
try this:
- (ibaction)createstory:(id)sender { nsstring* tempstr = [thetemplate.text stringbyreplacingoccurrencesofstring:@"<place>" withstring:theplace.text]; tempstr = [tempstr stringbyreplacingoccurrencesofstring:@"<verb>" withstring:theverb.text]; theoutput.text = [tempstr stringbyreplacingoccurrencesofstring:@"<number>" withstring:thenumber.text]; } does make sense? :)
Comments
Post a Comment