找不到对象时如何在 PFQueryTableViewController 中创建默认消息

how to create a default message in PFQueryTableViewController when no objects found

我希望使用 Parse PFQueryTableViewController 来显示存储在云中的项目列表。

但是,当没有项目时,我希望通过显示 "No Item Found" 的自定义表格视图单元格在表格视图中显示默认消息。

我正在寻找有关如何自定义 PFQueryTableViewController 以实现此目的的意见。

提前致谢

它可以通过一些额外的方法覆盖和一些小技巧来实现。我要补充一点,(imo)我们正在进入 iOS class 的 parse.com 专业化的净收益减少的领域。

// lie about the actual count
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if (self.objects.count) return [super tableView:tableView numberOfRowsInSection:section];
    return 1;
}

// answer a dummy object when there are none
- (PFObject *)objectAtIndexPath:(NSIndexPath *)indexPath {
    if (self.objects.count) return [super objectAtIndexPath:indexPath];
    return [PFObject objectWithClassName:[self parseClassName]];
}

// change how we behave for the dummy object
- (PFUI_NULLABLE PFTableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFUI_NULLABLE PFObject *)object {

    // check for your dummy object (it will be the only one with no id
    // return a special cell in that case
    if (!object.objectId) {
        // create and return the special custom cell here
        // if you're unsure about this, [see this SO answer][1]
    } else {
        PFTableViewCell *cell;
        // the regular cellForRowAtIndexPath behavior goes here
        return cell;
    }
}

就专门子class的成本效益而言,我什至对UITableViewController也有同样的感觉。使用包含 table 视图的常规 UIViewController 可以获得最多的控制(并且没有那么多额外的工作)。