我希望能够将一个单元格拖到另一个单元格上,当我释放它时,它会有效地“合并”这些单元格(显示不同的单元格)。我不确定 UITableView
是最好的控件还是 UICollectionView
。有人对如何进行有任何想法吗?
最佳答案
可能是我没有正确理解你,但正如我所理解的,你想通过拖动来合并单元格,所以为你实现一些代码。看看这个。
如果你想要这样的东西......
使用这样的编辑代码:---
ViewDidLoad 初始化数组并将表格设置为编辑模式:
fruitsArray=[[NSMutableArray alloc] initWithObjects:@"Apple",@"Banana",@"Mango",@"Guava",@"PineApple",@"Watermelon",@"Grapes",@"GroundNut",@"Muskmelon",@"Orange",@"Cherry",nil];
[tblView setEditing:YES];
tableView 的数据源设置为:->
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleNone;
}
- (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
if (sourceIndexPath.row!=destinationIndexPath.row) {
NSString *sourceString=[fruitsArray objectAtIndex:sourceIndexPath.row];
NSString *destinationString=[fruitsArray objectAtIndex:destinationIndexPath.row];
destinationString=[destinationString stringByAppendingFormat:@",%@",sourceString];
[fruitsArray replaceObjectAtIndex:destinationIndexPath.row withObject:destinationString];
[fruitsArray removeObjectAtIndex:sourceIndexPath.row];
[tblView reloadData];
}
}
试试这个 sampleCode
关于iphone - 合并 UITableViewCells,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16248778/