TableView中,字典,数组的套用........
例:在大数组中建立多个小数组,每个小数组中包含着字典........
_tableArray = [[NSMutableArray alloc] init];
NSMutableDictionary *dic1 = [NSMutableDictionary dictionary];
[dic1 setObject:@"1.jpg" forKey:@"imageName"];
[dic1 setObject:@"刘大" forKey:@"name"];
[dic1 setObject:@"男" forKey:@"sex"];
NSMutableDictionary *dic2 = [NSMutableDictionary dictionary];
[dic2 setObject:@"1.jpg" forKey:@"imageName"];
[dic2 setObject:@"王二" forKey:@"name"];
[dic2 setObject:@"男" forKey:@"sex"];
NSMutableArray *array = [NSMutableArray array];
[array addObject:dic1];//将字典放入小数组中
[_tableArray addObject:array];//再将小数组放入大字典中
NSMutableArray *array2 = [NSMutableArray array];
[array addObject:dic2];
[_tableArray addObject:array2];
TableView中的其他空件....
//增加或者删除状态
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
//return UITableViewCellEditingStyleDelete;//删除
return UITableViewCellEditingStyleInsert;//增加
}
reloadData;//把tableView所有的协议重新走一遍
//编辑"删除"按钮文字
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
return @"Very Good";//按钮改由delete改变成“Very Good”
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{
//[_tableArray exchangeObjectAtIndex:sourceIndexPath.row withObjectAtIndex:destinationIndexPath.row];//只是交换了数组的元素
id value = [[_tableArray objectAtIndex:sourceIndexPath.row]retain];
NSLog(@"value1 == %d",[value retainCount]);
[_tableArray removeObjectAtIndex:sourceIndexPath.row];
NSLog(@"value2 == %d",[value retainCount]);
[_tableArray insertObject:value atIndex:destinationIndexPath.row];
NSLog(@"value3 == %d",[value retainCount]);
[value release];
}