简体   繁体   中英

how to replace the part of string from NSMutablestring

Iam developing one application.In that i take the string from array and replace.xml from that string and go to next page.And if i come back and execute that code the application will be crashed at that replace string line.Below is my code.

  -(void)open:(UITapGestureRecognizer*)recognizer
  {
       NSInteger i=(recognizer).view.tag;
       NSMutableString *s1=[listoflessons objectAtIndex:i];
       [default1 setObject:s1 forKey:@"KeyToXmlFile"];
       NSLog(@"%@",[default1 objectForKey:@"KeyToXmlFile"]);
        [s1 replaceCharactersInRange:[s1 rangeOfString: @".xml"] withString: @""];
        [default1 setObject:s1 forKey:@"KeyToSelectedFile"];
        [listoflessons removeObjectAtIndex:i];
      [listoflessons insertObject:[default1 objectForKey:@"KeyToXmlFile"] atIndex:i];
        NSLog(@"%@",listoflessons);
       SecondViewCOntroller *snd=[[SecondViewCOntroller    alloc]initWithNibName:@"SecondViewCOntroller" bundle:nil];
       [self.navigationController pushViewController:snd animated:YES];
      }

so please tell me how to avoid that one.

my guess is that the objects in "listoflessons" are of type NSString and not NSMutableString.

try replacing this line:

   NSMutableString *s1=[listoflessons objectAtIndex:i];

with this:

   NSMutableString *s1=[[NSMutableString alloc] initWithString:[listoflessons objectAtIndex:i]];

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