0

我正在开发一个应用程序。我从数组中获取字符串并从该字符串中替换 .xml 并转到下一页。如果我回来执行该代码,应用程序将在该替换字符串行崩溃。下面是我的代码.

  -(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];
      }

所以请告诉我如何避免那个。

4

1 回答 1

1

我的猜测是“listoflessons”中的对象是 NSString 类型而不是 NSMutableString。

尝试替换这一行:

   NSMutableString *s1=[listoflessons objectAtIndex:i];

有了这个:

   NSMutableString *s1=[[NSMutableString alloc] initWithString:[listoflessons objectAtIndex:i]];
于 2012-04-05T13:10:40.400 回答