我正在尝试使用(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
自定义PFObject
中PFQueryTableViewController
数据的显示。因此,我在自己的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/