如何通过tableview索引过滤Parse查询? [英] How to filter a Parse query by an tableview index?

查看:65
本文介绍了如何通过tableview索引过滤Parse查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有一个UITableViewController.在此表中,我正在执行此解析查询:

I have a UITableViewController in my application. In this Table i am performing this Parse Query:

-(IBAction)joinEvent:(id)sender {


PFQuery *query = [PFQuery queryWithClassName:@"Event"];
[query selectKeys:@[@"Vacants"]];
[query whereKey:@"Username" equalTo:PFUser.currentUser.username];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {
        // The find succeeded.
        NSLog(@"Successfully retrieved %lu scores.", (unsigned long)objects.count);
        // Do something with the found objects


        for (NSObject *object in objects){

            NSString *a = [object valueForKey:@"Vacants"];
            NSLog(@"vacants %@", a);


        }
    } else {
        // Log details of the failure
        NSLog(@"Error: %@ %@", error, [error userInfo]);
    }

    [self.tableView reloadData];
}];

}

此查询使我获得了解析云中的所有空缺.

This query gets me all the vacants in my parse cloud.

我想要的是能够获取表中某个IndexPath.row的空缺.

What i want is to be able to just get the vacants for a certain IndexPath.row of my table.

到目前为止,我已经尝试使用

So far I have tried to use the

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath; 

代替IBAction,但结果相同.但是使用这种方法,我不知道如何从IBAction调用didSelectRowAtIndexPath,我相信它将解决我的问题.

instead of the IBAction, but still the same result. But using this approach i don't know how to call the didSelectRowAtIndexPath from the IBAction, which i believe it would solve my issue.

这是我的cellForRowAtIndexPath方法:

This is my cellForRowAtIndexPath method:

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *cellID = @"cell";

TFGResultsTableViewCell *cell= [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];

if(cell == nil) {
    cell = [[TFGResultsTableViewCell alloc]
            initWithStyle:UITableViewCellStyleDefault
            reuseIdentifier:cellID];
}

// Configure the cell...

cell.eventnamelabel.text = [eventnameArray objectAtIndex: [indexPath row]];

cell.userLabel.text = [userArray objectAtIndex: [indexPath row]];
cell.sportLabel.text = [sportArray objectAtIndex: [indexPath row]];
cell.eventDateLabel.text = [dateArray objectAtIndex: [indexPath row]];
cell.eventHourLabel.text = [hourArray objectAtIndex: [indexPath row]];
cell.eventPlaceLabel.text = [placeArray objectAtIndex: [indexPath row]];
cell.vacantsLabel.text = [vacantsArray objectAtIndex: [indexPath row]];
cell.cityLabel.text = [cityArray objectAtIndex: [indexPath row]];

if([cell.sportLabel.text isEqualToString:@"Soccer" ]){

    cell.eventImage.image = [UIImage imageNamed:@"SoccerBallIcon.png"];
}
else{

    cell.eventImage.image = [UIImage imageNamed:@"icon.png"];

}

return cell;

}

推荐答案

将来自解析服务器的数据添加到全局数组并通过代码或在中设置表视图的委托木板.

Add the data from the parse server to a global Array and set the delegate for the table view via code or in soryboard.

NSArray *copyArray = objects;
yourtableview.delegate = self ;

在您的委托方法中-

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
     NSString *a = [[copyArray objectAtIndex:indexPath.row]valueForKey:@"Vacants"];
}

这篇关于如何通过tableview索引过滤Parse查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆