title: PFQueryTablViewController queryForTable method with network reachability
body: <p>I am trying to populate a PFQueryTableViewController with Question objects from my Parse backend.  How do I implement blocks within this method?  </p>
  
  <pre><code>- (PFQuery *)queryForTable  // I'm having issues with using the method "findObjectInBackgroundWithBlock" in this method.
  {
      PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
  
      [query fromLocalDatastore];
      [query orderByDescending:@"createdAt"];
  
      [query findObjectsInBackgroundWithBlock:^(NSArray *parseQuestions, NSError *error) { // Fetch from local datastore
          if (parseQuestions != nil) {
              NSMutableArray *mutableParseQuestions = [parseQuestions mutableCopy];
              self.questions = mutableParseQuestions;  // if Set local array to fetched Parse questions
  
          } else {
  
              if ([InternetReachabilityManager isReachable]) {
  
                  [query findObjectsInBackgroundWithBlock:^(NSArray *parseQuestions, NSError *error) { // Fetch from Cloud
                        NSMutableArray *mutableParseQuestions = [parseQuestions mutableCopy];
                        self.questions = mutableParseQuestions;  // if Set local array to fetched Parse questions
                        [Question pinAllInBackground:parseQuestions];  // Save query results to local datastore
  
                  }];
              }
          }
      }];
  
      return query;
  }
  </code></pre>
  
  <p>When blocks are in this method I get this error.
  <a href="https://i.stack.imgur.com/9SJnC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9SJnC.png" alt="enter image description here"></a></p>
  
  <p>Is this because queryForTable is already a background process?  Should I just use </p>
  
  <blockquote>
    <p>[query findObjects]</p>
  </blockquote>
  
  <p>Also, I'm trying to implement reachability into my fetch.  </p>
  
  <ol>
  <li>Try fetching from local datastore </li>
  <li>Load data into table if they are there else switch to the network </li>
  <li>Call block if network is available</li>
  <li>Save the results of the network fetch into the local datastore</li>
  </ol>
  
  <p>I know that this method is supposed to automatically assign objects it fetches to rows but I don't know how to work with it if we're passing around a PFObject subclass object.  This is my explanation for the arrays.</p>
  
  <pre><code>- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  
      self.question = [self.questions objectAtIndex:indexPath.row]; // Save one question from row
  
      static NSString *identifier = @"QuestionsCell";
  
      QuestionsCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  
      if (cell == nil) {
          cell = [[QuestionsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
      }
  
      [cell setQuestion:self.question];  //
  
      return cell;
  }
  </code></pre>
  
  <p>This is how I use the fetched array to populate the tableView.</p>
  
  <p>So my questions:</p>
  
  <ol>
  <li>Why can't I call a block inside of queryForTable?</li>
  <li>Is there any way I can make this simpler by using queryForTable's automatic assigning of objects to rows?</li>
  <li>If the internet is unreachable and the local datastore is empty what should I do?</li>
  </ol>