YapDatabase排序会混淆编辑更新

时间:2016-12-07 10:34:53

标签: ios uitableview yapdatabase

UITableViewController我使用YapDatabase和Mantle排序方式如下:

YapDatabaseViewSorting *viewSorting = [YapDatabaseViewSorting withObjectBlock:^NSComparisonResult(NSString *group, NSString *collection1, NSString *key1, XQBuilding *object1, NSString *collection2, NSString *key2, XQBuilding *object2) {
    if ([group isEqualToString:XQBuildingsViewGroupName]) {
        return [[object1 name] compare:[object2 name] options:NSNumericSearch];
    }
    if ([group isEqualToString:XQPicturesGroup]) {
        return [[object1 updatedAt] compare:[object2 updatedAt]];
    }
    return NSOrderedSame;
}];
YapDatabaseViewOptions *options = [[YapDatabaseViewOptions alloc] init];
options.isPersistent = NO;

YapDatabaseView *databaseView = [[YapDatabaseView alloc] initWithGrouping:viewGrouping sorting:viewSorting versionTag:@"" options:options];

虽然我有时使用的选项(当编辑的名称更改列表中已编辑的项目顺序时)在阅读时不正确indexPath

    - (UITableViewCell*)editableTableView:(UITableView *)tableView simpleCellForIndexPath:(NSIndexPath *)indexPath
    {
        __block XQBuilding *building;
        __block NSNumber *gla;
        [self.readConnection readWithBlock:^(YapDatabaseReadTransaction *transaction) {
            building = [[transaction ext:XQBuildingListYapName] objectAtIndexPath:indexPath withMappings:self.tableViewAnimator.viewMappings];
            gla = [building glaWithTransaction:transaction];
        }];

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BuildingCell"];
        cell.textLabel.text = building.name;
        cell.detailTextLabel.text = [NSString stringWithFormat: @"%@ sqm", formatDecimal(gla)];
        return cell;
    }

我。即在这种情况下,building与编辑的不同。如何根据实际排序获得正确的indexPath

1 个答案:

答案 0 :(得分:0)

有很多东西应该正确编码,以使其正常工作!

正如我从您的代码中看到的那样,您使用了YapDatabaseViewMappings。您是否使用LongLivedReadTransactions并订阅YapDatabaseModifiedNotification以正确修改数据库更改表?

有一个simplified example that shows如何使用所有这些东西在数据库更新后立即实时更新UITableView