使用segue信息Parse.com在PFQueryTableViewController中加载查询

时间:2014-06-10 16:43:54

标签: ios objective-c xcode parse-platform pfquery

我在一段时间内一直在寻找这个,但没有发现任何相关信息。我想使用PFQueryTableViewController构建一个表,但我的Query中用于构建此表的一些信息在前一个ViewController中由segue传递。问题是程序在获取有关segue的信息之前加载Query,因此Query每次都会导致空搜索。

这是我在第一个ViewController中的segue:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"vai"]) {
      NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    yTableViewController *destViewController = segue.destinationViewController;

PFObject *object = [self.objects objectAtIndex:indexPath.row];

locallabel = [object objectForKey:@"local"];

destViewController.lugar = locallabel;

}

这是我在下一个视图中的Query,即PFQueryTableViewController

@interface yTableViewController ()
@property (nonatomic, strong) NSMutableIndexSet *optionIndices;
@end

@implementation yTableViewController

@synthesize segint;

- (id)initWithCoder:(NSCoder *)aCoder
{
    self = [super initWithCoder:aCoder];
    if (self) {
    // Custom the table

    // The className to query on
    self.parseClassName = @"Pedidos";

   // self.parseClassName = @"Locais";

    // The key of the PFObject to display in the label of the default cell style
    self.textKey = @"local";

    // Whether the built-in pull-to-refresh is enabled
    self.pullToRefreshEnabled = YES;

    // Whether the built-in pagination is enabled
    self.paginationEnabled = YES;

    // The number of objects to show per page
    self.objectsPerPage = 10;
}
return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];


}

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {

    // Custom initialization
    }
return self;
}



// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;

// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;


- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (PFQuery *)queryForTable
{
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
[query whereKey:@"local" equalTo:lugar]; //this is the problem of everything, when i try to find some items where the key @"local" is equal to an NSString defined in the previous PFQueryTableVC and passed from segue


if (self.objects.count == 0) {
    query.cachePolicy = kPFCachePolicyCacheThenNetwork;
}

[query orderByDescending:@"createdAt"];


   if ([self.objects count] == 0) {
 query.cachePolicy = kPFCachePolicyCacheThenNetwork;
 }

//    [query orderByAscending:@"name"];

return query;
}

如何在程序构建Query以安装表之前加载segue?

PS。我已经尝试在perfomseguewithidentifier方法中执行DidselectrowatindexPath,但我认为问题不是我发送信息的方式,而是我检索信息的时间

1 个答案:

答案 0 :(得分:0)

我没有看到[query findObjects:]在任何地方被调用。现在你的查询什么也没做。此外,您的问题可能是您在将查询返回结果之前将数据加载到表中。你能发布一下如何/何时将数据加载到表中的代码吗?