正如 vignesh 所说, Key 应该是唯一的,因此不能更改,但可以更改其内容:
NSMutableDictionary *dic=[[NSMutableDictionary alloc] initWithObjectsAndKeys:a1,@"0",a2,@"1",a3,@"2",a4,@"3", nil];
NSMutableDictionary *userbtn=[[NSDictionary alloc] initWithObjectsAndKeys:dic,@"button", nil];
[[NSUserDefaults standardUserDefaults] registerDefaults:userbtn];
现在
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
NSUInteger fromRow = [sourceIndexPath row];
NSString *fromstr = [[userbtn objectForKey:@"button"]objectForKey:[NSString stringWithFormat:@"%d",fromRow]]; // firstly take content at index before interchanging
NSUInteger toRow = [destinationIndexPath row];
NSString *tostr = [[userbtn objectForKey:@"button"]objectForKey:[NSString stringWithFormat:@"%d",toRow]]; // firstly take content at index before interchanging
[[userbtn objectForKey:@"button"] setObject:fromstr forKey:[NSString stringWithFormat:@"%d",toRow]]; //interchange value but key is same
[[userbtn objectForKey:@"button"] setObject:tostr forKey:[NSString stringWithFormat:@"%d",fromRow]];//interchange value but key is same
}