29,028
社区成员
发帖
与我相关
我的任务
分享
@property (strong, nonatomic) NSMutableArray *dicarray;
-(void)parsingJson
{
NSUserDefaults *Store_Update = [NSUserDefaults standardUserDefaults];
id jsonObject=[Store_Update objectForKey:@"json"];
if ([jsonObject isKindOfClass:[NSDictionary class]])
{
NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithDictionary:jsonObject];
self.dicarray=[dictionary objectForKey:@"Name"];
}else
{
NSLog(@"ぶしで");
}
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if(editingStyle==UITableViewCellEditingStyleDelete)
{
[self.dicarray removeObjectAtIndex:[indexPath row]];
}
[self.tableview deleteRowsAtIndexPaths:self.dicarray withRowAnimation:UITableViewRowAnimationAutomatic];
[tableView reloadData];
}
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(@"ぶしで");
}
删除的问题已经解决了,取值的时候转一下就好了,这样还是存在问题,删除后再次返回到这个页面数据没更新。 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];
self.dicarray =[[NSMutableArray alloc] initWithCapacity:0];
之后的其它代码不变,再运行试试NSMutableArray *Variablearray=[NSMutableArray arrayWithArray:self.dicarray];
if(editingStyle==UITableViewCellEditingStyleDelete)
{
[Variablearray removeObjectAtIndex:[indexPath row]];
[self.tableview deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
if(editingStyle==UITableViewCellEditingStyleDelete)
{
[self.dicarray removeObjectAtIndex:[indexPath row]];
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
}
在删除行是有动画效果,如果你的数据源及UI都实际已经移除掉了该行,后面也就没必要再重新reloadData