我用ARC创建了一个简单的项目,其中我有UITableView
. 我NSMutableArray
有NSMutableDictionary
。
像
(
{
comment = "";
"field_name" = "field_name 1";
"main_id" = 1;
"order_index" = 0;
"picker_value" = "";
},
{
comment = "";
"field_name" = "field_name 2";
"main_id" = 2;
"order_index" = 1;
"picker_value" = "";
},
{
comment = "";
"field_name" = "field_name 3";
"main_id" = 3;
"order_index" = 2;
"picker_value" = "";
},
{
comment = "";
"field_name" = "field_name 4";
"main_id" = 4;
"order_index" = 3;
"picker_value" = "";
},
)
键"field_name"
的值显示在 my 的每个单元格上UITableView
。它工作正常。但我想在我的UITableViewCell
.
例如:
1 value - 0 order_index
2 value - 1 order_index -----
3 value - 2 order_index |-> I Want to swap value 2 to 4…(But do not want to change order_index)
4 value - 3 order_index -----
It should Be
1 value - 0 order_index
4 value - 1 order_index
3 value - 2 order_index
2 value - 3 order_index
value of dictionary will swap but do not want to change order_index
我知道的方法UITableView
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row > self.MyArray.count-1)
return NO;
return YES;
}
// Process the row move. This means updating the data model to correct the item indices.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
toIndexPath:(NSIndexPath *)toIndexPath
{
// here i get fromIndexPath.row and toIndexPath.row
NSMutableDictionary *oldDict = [NSMutableDictionary dictionary];
oldDict = [(NSMutableDictionary *)[self.listOfReportField objectAtIndex:fromIndexPath.row] copy];
[self.myArray removeObject:oldDict];
[self.myArray insertObject:[self.myArray objectAtIndex:toIndexPath.row-1] atIndex:fromIndexPath.row];
[self.myArray insertObject:oldDict atIndex:toIndexPath.row];
// Here i am not swap my row , what should be i need to do here ??
}
b 作为我的要求,我首先要交换 value
字典,但不是order_index
在这里。我无法交换价值。
请给我建议。
提前致谢。