如何通过tableview索引过滤Parse查询?

时间:2015-04-01 12:14:17

标签: objective-c uitableview parse-platform

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

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

}

这个查询让我得到了解析云中的所有空缺。

我想要的是能够获得我桌子的某个IndexPath.row的空位。

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

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

而不是IBAction,但结果仍然相同。但是使用这种方法我不知道如何从IBAction调用didSelectRowAtIndexPath,我相信它可以解决我的问题。

这是我的cellForRowAtIndexPath方法:

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

}

1 个答案:

答案 0 :(得分:1)

将数据从解析服务器添加到全局数组,并通过代码或在soryboard中为表视图设置委托。

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

在你的delegateMethod -

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