本帖最后由 ningshuang520 于 2014-10-15 20:17:26 编辑

解决方案 »

  1.   

     if(editingStyle==UITableViewCellEditingStyleDelete)
        {
            [self.dicarray removeObjectAtIndex:[indexPath row]];
           [tableView deleteRowsAtIndexPaths:@[indexPath]
                             withRowAnimation:UITableViewRowAnimationAutomatic];
        }
    不需要reloadData吧
      

  2.   

    确保你的self.dicarray 是个可变数组(NSMutableArray). 删除时可这样
    if(editingStyle==UITableViewCellEditingStyleDelete)
        {
            [self.dicarray removeObjectAtIndex:[indexPath row]];
           [self.tableView beginUpdates];
           [self.tableView deleteRowsAtIndexPaths:@[indexPath]
                             withRowAnimation:UITableViewRowAnimationAutomatic];
           [self.tableView endUpdates];
        }在删除行是有动画效果,如果你的数据源及UI都实际已经移除掉了该行,后面也就没必要再重新reloadData
      

  3.   

    self.dicarray的数据是从JSON中取的,我在上面的方法中,取值的时候就用的NSMutableArray,难道是这的问题。
      

  4.   

    额,这个改了还是报这个错,难道是从取的数据的问题?
    NSMutableArray *Variablearray=[NSMutableArray arrayWithArray:self.dicarray];
        if(editingStyle==UITableViewCellEditingStyleDelete)
        {
            [Variablearray removeObjectAtIndex:[indexPath row]];
            [self.tableview deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
        }
      

  5.   

    请问从JSON中取的数组是不能直接进行删除操作的么,这个不知道是不是这个原因。
      

  6.   

    请问从JSON中取的数组是不能直接进行删除操作的么,这个不知道是不是这个原因。
    问题在于所有从NSUserDefaults返回的值全部是immutable(不可变)的,所以在修改数组时会出现这个问题。你可以尝试在使用self.dicarray之前先实例化一下
    self.dicarray =[[NSMutableArray alloc] initWithCapacity:0];
    之后的其它代码不变,再运行试试
      

  7.   

    JSON取的数组应该是可以进行删除操作的
      

  8.   

    楼主,你好。我注意到了NSMutableArray  * dicarray;是没有实例化变量的。
      

  9.   


    NSUserDefaults *Store_Update = [NSUserDefaults standardUserDefaults];
        id jsonObject=[Store_Update objectForKey:@"json"];
        if ([jsonObject isKindOfClass:[NSDictionary  class]])
        {
           NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithDictionary:jsonObject];
           NSMutableArray *dicarray=[dictionary objectForKey:@"Name"];
           self.Variablearray=[NSMutableArray arrayWithArray:dicarray];
        }else
        {
            NSLog(@"ぶしで");
        }
    删除的问题已经解决了,取值的时候转一下就好了,这样还是存在问题,删除后再次返回到这个页面数据没更新。
      

  10.   

    Show the Breakpoint navigator(项目ios device下面那个左平右尖那个按键),左下角,+,Add Exception Breakpoint。做完上面的操作,重新debug程序吧,然后再崩溃的会运气不差的话,就会直接定位到出错的代码。
      

  11.   

    以前写demo时候遇到过,从[NSUserDefaults standardUserDefaults]中取出的字典不管你存的时候是什么格式,取出来就变成了NSDictionary而不是NSMutableDictionary,数组同理。
      

  12.   

    删除后的数据又更新到NSUserDefaults 中了吗? 如果没有,显示的数据还是原来没更新过的。
      

  13.   

    请问这个数组再往回更新NSUserDefaults中该怎么操作,求指导。
      

  14.   


    ok,解决了。 NSMutableDictionary *jsdiction=[[NSMutableDictionary alloc]init];
            [jsdiction setValue:self.Variablearray forKey:@"Name"];
            NSLog(@"======jsdiction:%@\nVariablearray:%@",jsdiction,self.Variablearray);
            NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
           [userDefaults setObject:jsdiction forKey:@"json"];
            [userDefaults synchronize];