@Override
 public double getHeightForRow(UITableView tableView, NSIndexPath indexPath) {
   if (indexPath.getRow() < getObjects().size()) {
     return PAPFindFriendsCell.getHeightForCell();
   } else {
     return 44;
   }
 }
 private void shouldToggleFollowFriendForCell(final PAPFindFriendsCell cell) {
   PAPUser cellUser = cell.getUser();
   if (cell.getFollowButton().isSelected()) {
     // Unfollow
     cell.getFollowButton().setSelected(false);
     PAPUtility.unfollowUserEventually(cellUser);
     PAPNotificationManager.postNotification(PAPNotification.USER_FOLLOWING_CHANGED);
   } else {
     // Follow
     cell.getFollowButton().setSelected(true);
     PAPUtility.followUserEventually(
         cellUser,
         new PFSaveCallback() {
           @Override
           public void done(boolean success, NSError error) {
             if (error == null) {
               PAPNotificationManager.postNotification(PAPNotification.USER_FOLLOWING_CHANGED);
             } else {
               cell.getFollowButton().setSelected(false);
             }
           }
         });
   }
 }
  @Override
  public PFTableViewCell getCellForRow(
      final UITableView tableView, final NSIndexPath indexPath, final PAPUser user) {
    final String friendCellIdentifier = "FriendCell";

    PAPFindFriendsCell cell =
        (PAPFindFriendsCell) tableView.dequeueReusableCell(friendCellIdentifier);
    if (cell == null) {
      cell = new PAPFindFriendsCell(UITableViewCellStyle.Default, friendCellIdentifier);
      cell.setDelegate(this);
    }

    cell.setUser(user);

    cell.getPhotoLabel().setText("0 photos");

    PAPUserAttributes attributes = PAPCache.getSharedCache().getUserAttributes(user);

    if (attributes != null) {
      // set them now
      int count = PAPCache.getSharedCache().getUserPhotoCount(user);
      cell.getPhotoLabel().setText(String.format("%d photo%s", count, count == 1 ? "" : "s"));
    } else {
      synchronized (this) {
        Boolean outstandingCountQueryStatus = outstandingCountQueries.get(indexPath);
        if (outstandingCountQueryStatus == null || !outstandingCountQueryStatus) {
          outstandingCountQueries.put(indexPath, true);
          PFQuery<PAPPhoto> photoNumQuery = PFQuery.getQuery(PAPPhoto.class);
          photoNumQuery.whereEqualTo(PAPPhoto.USER_KEY, user);
          photoNumQuery.setCachePolicy(PFCachePolicy.CacheThenNetwork);
          photoNumQuery.countInBackground(
              new PFCountCallback() {
                @Override
                public void done(int count, NSError error) {
                  synchronized (PAPFindFriendsViewController.this) {
                    PAPCache.getSharedCache().setUserPhotoCount(user, count);
                    outstandingCountQueries.remove(indexPath);
                  }
                  PAPFindFriendsCell actualCell =
                      (PAPFindFriendsCell) tableView.getCellForRow(indexPath);
                  actualCell
                      .getPhotoLabel()
                      .setText(String.format("%d photo%s", count, count == 1 ? "" : "s"));
                }
              });
        }
      }
    }

    cell.getFollowButton().setSelected(false);
    cell.setTag(indexPath.getRow());

    if (followStatus == PAPFindFriendsFollowStatus.SOME) {
      if (attributes != null) {
        cell.getFollowButton().setSelected(PAPCache.getSharedCache().getUserFollowStatus(user));
      } else {
        synchronized (this) {
          final PAPFindFriendsCell c = cell;

          Boolean outstandingQuery = outstandingFollowQueries.get(indexPath);
          if (outstandingQuery == null || !outstandingQuery) {
            outstandingFollowQueries.put(indexPath, true);
            PFQuery<PAPActivity> isFollowingQuery = PFQuery.getQuery(PAPActivity.class);
            isFollowingQuery.whereEqualTo(PAPActivity.FROM_USER_KEY, PAPUser.getCurrentUser());
            isFollowingQuery.whereEqualTo(PAPActivity.TYPE_KEY, PAPActivityType.FOLLOW.getKey());
            isFollowingQuery.whereEqualTo(PAPActivity.TO_USER_KEY, user);
            isFollowingQuery.setCachePolicy(PFCachePolicy.CacheThenNetwork);

            isFollowingQuery.countInBackground(
                new PFCountCallback() {
                  @Override
                  public void done(int count, NSError error) {
                    synchronized (this) {
                      outstandingFollowQueries.remove(indexPath);
                      PAPCache.getSharedCache()
                          .setUserFollowStatus(user, error == null && count > 0);
                    }
                    if (c.getTag() == indexPath.getRow()) {
                      c.getFollowButton().setSelected(error == null && count > 0);
                    }
                  }
                });
          }
        }
      }
    } else {
      cell.getFollowButton().setSelected(followStatus == PAPFindFriendsFollowStatus.ALL);
    }

    return cell;
  }