ios - parse.com PFQueryTableViewController多次返回同一对象

标签 ios parse-platform pfquery

我正在尝试使用(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object自定义PFObjectPFQueryTableViewController数据的显示。因此,我在自己的PFQuery (PFQuery *)queryForTable中的PFQueryTableViewController中构造了自己的delegate对象,该对象应该在NSArray中获取多个对象。

我认为parse.com应该为返回的每个对象发送/调用(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object一次。但是,我发现它多次返回同一对象。

因此,例如,我得到了相同的对象,而不是3次调用(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object的3个不同的对象。但这不是数据或查询的问题,因为在(PFQuery *)queryForTable的末尾,就在

return query;

我试过了
[query findObjectsInBackgroundWithBlock:^(NSArray *resultsNow,NSError *error) {NSLog(@"We have the following: %@", resultsNow);}];
 sleep(5);

这显示了正确获得的3个对象。通过PFQueryTableViewController调用(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object 3次而不是一一发送3个对象,而是发送3个第一个对象,完全相同的查询又如何呢?

为了回应Wain的问题,我在评论中添加了一些答案,但以下内容似乎也很相关:
- (PFObject *)objectAtIndex:(NSIndexPath *)indexPath {
// overridden, since we want to implement sections
if (indexPath.section < self.objects.count) {
    return [self.objects objectAtIndex:indexPath.section];
}

return nil;
}

最佳答案

我有一个类似的问题,我所做的是:

1-不用常规的PFQueryTableViewController而不是UITableViewController

2-将方法queryForTable:更改为(void)
- (void)queryForTable {
3-删除PFQueryTableView方法并实现DataSource方法。

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    {
    }
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
    }
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
    }

在.h文件中声明后,在[self queryForTable]中调用viewDidLoad

如果不使用块,则只需创建NSArray property并在queryForTable上进行填充:
self.yourarray = [query findobjects];
如果使用块,只需确保在块内填充NSArray并重新加载tableview。
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {

    if (error) {
        // There was an error, do something with it.
    }
    else {
        self.yourArray = objects;
    }
    // Reload your tableView Data
    dispatch_async(dispatch_get_main_queue(), ^{
        [self.tableView reloadData];
    }); 
}];

这就是我的工作方式。希望能帮助到你。

关于ios - parse.com PFQueryTableViewController多次返回同一对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21000605/

相关文章:

ios - CoreData 按关系排序

iOS保存标签数据

ios - iOS 中如何获取两个地点之间的路线?

java - 将 Parse.com 中的日期设置为与系统日期相同的类型

ios - 如何在 IOS 中使用解析进行 PFRelation 或关系数据库查询

ios - 创建自定义 UIView 时,您应该为该自定义 UIView 创建一个实例变量还是只使用参数

ios - 解析查询不显示最新数据

swift - 只加载前 10 个帖子,然后加载更多 - parse.com

ios - 如何检查日期条目是否早于今天的日期

ios - 使用 Parse 在 PFQuery 之外重新调整空白数组的数组。