简体   繁体   中英

Load a Query in PFQueryTableViewController using segue information Parse.com

I was looking for this in a while and didn't find anything about it. I want to build a table using the PFQueryTableViewController , but some informations in my Query to build this table are passed by segue in the previous ViewController . The problem is the program load the Query before get the information on the segue, so the Query results in a null search every time.

That's my segue in the first ViewController :

- (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;

}

and this is my Query in the next View, which is the 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;
}

How can I load the segue before the program build the Query to mount the Table?

PS. I already tried to do a perfomseguewithidentifier in the DidselectrowatindexPath method, but I think that the problem is not how I am sending the information, but the time I am retrieving it

I don't see [query findObjects:] getting called anywhere. Right now your query does nothing. Also your issue might be that you are loading data into the table before query can come back with the result. Can you post the code of how/when you are loading data into the table?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM