【问题标题】:NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]'NSArrayM objectAtIndex:]: 索引 2 超出范围 [0 .. 1]'
【发布时间】:2013-09-17 06:58:38
【问题描述】:

所以我试图编辑我用 PFQuery(parse.com) 创建的数组。我需要检查它,然后从中删除对象,然后在 UITableView 中显示它,但是当我运行它时,我得到了这个错误

- (PFQuery *)queryForParse
{
    PFQuery *query1 = [PFQuery queryWithClassName:self.parseClassName];

    //[query1 selectKeys: [NSArray arrayWithContentsOfFile:[ NSString @"checkMark"]]];

    [query1 whereKey:@"location" nearGeoPoint:[PFGeoPoint geoPointWithLatitude:[LocationController sharedSingleton].locationManager.location.coordinate.latitude longitude:[LocationController sharedSingleton].locationManager.location.coordinate.longitude] withinMiles:50];
    [query1 findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error){

            placesArray = [[NSMutableArray alloc] initWithArray:objects];
            NSMutableArray *toDelete = [NSMutableArray array];

            for (PFObject *tempObject in placesArray){
                if ([tempObject objectForKey:@"checkMark"] == nil){
                    [toDelete addObject:tempObject];
                }
            }
            [placesArray removeObjectsInArray:toDelete];
            NSLog(@"%@", placesArray);
        }
        [placesTable reloadData];
    }];
    return query1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    PlacesTableCell *cell = (PlacesTableCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil){
        cell = [[PlacesTableCell alloc] init];
    }

    PFObject *tempObject = [placesArray objectAtIndex:indexPath.row];
    cell.message.text = [tempObject objectForKey:@"message"];

    return cell;
}

【问题讨论】:

  • 你的“numberOfRowsInSection:”方法是什么样的?
  • 我对 Objective C 还很陌生,所以我仍在努力解决所有问题。

标签: objective-c uitableview nsmutablearray parse-platform pfquery


【解决方案1】:

听起来你可能只需要添加那个“numberOfRowsInSection:”方法。

例如:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // assuming only one section and one table here
    return([placesArray count]);
}

【讨论】:

  • 谢谢!我一直在为此扯头发哈哈
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-13
  • 1970-01-01
  • 1970-01-01
  • 2012-09-20
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多