简体   繁体   中英

problem while adding textfield text to NSMutablestring

i need to add textfield text to NSMutable string when end of the textfield end.

for that i use the code

- (IBAction)my_textfield_editing {
    if ([my_textfield.text length]!=0) {
        [my_string appendString:my_textfield.text];
        NSLog(@"mystring %@",my_string);
    }
}

give this to textfield EditingDidEnd.

but i got some problem here.

for first editing it adds string as string1.

for second editing it adds string as string1string1,string2.

for third editing it adds string as string1string1,string2string1,string2,string3

i think it repeats with previous string.

i am trying placing my_string = NULL before adding it

if i use it always shows null.

how can i resolve it.

can any one help me.

Thank u in advance.


appendString: method won't work if you assign Null to a NSMutableString' . In order to make it work, you have to initialize it with some default string. In your case an empty string (ie., @"" ). For example, you have to initialize the mutable string like the following.

my_sms_string = [[NSMutableString alloc] initWithString:@""];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM