iphone - 合并 UITableViewCells

标签 iphone ios uitableview

我希望能够将一个单元格拖到另一个单元格上,当我释放它时,它会有效地“合并”这些单元格(显示不同的单元格)。我不确定 UITableView 是最好的控件还是 UICollectionView。有人对如何进行有任何想法吗?

最佳答案

可能是我没有正确理解你,但正如我所理解的,你想通过拖动来合并单元格,所以为你实现一些代码。看看这个。

如果你想要这样的东西......

Screenshot

使用这样的编辑代码:---

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/

相关文章:

ios - iOS 版本的 Twitter 个人资料屏幕是如何构建的?

iphone - 解析包含多个对象的 JSON 字符串

iphone - 无法移动 Sprite Kit 中的对象

ios - 我想要一个 UIView 覆盖整个屏幕甚至导航栏,但显示它的 subview

iphone - iAd 断网后刷新

ios - 调用 dequeueReusableCellWithReuseIdentifier :forIndexPath: 时由于未捕获的异常 'NSRangeException' 终止应用程序

ios - UILabel 显示错误

ios - 如何在 UITableViewController 中实现搜索栏?

ios - 由于尝试写入我认为是可变字典的内容,当我重新进入 TableViewController 时崩溃

ios - 在字典数组中查找字典的索引