@Override
 public void didSelectRow(UITableView tableView, NSIndexPath indexPath) {
   if (tableItems.get(indexPath.getRow()) instanceof StringSelectionCell) {
     ((StringSelectionCell) tableItems.get(indexPath.getRow())).tap();
   }
   tableView.deselectRow(indexPath, true);
 }
 @Override
 public double getHeightForRow(UITableView tableView, NSIndexPath indexPath) {
   if (tableItems.size() == 1 && tableItems.get(0) instanceof SpinnerCell) {
     return tableView.getFrame().getHeight();
   }
   return tableItems.get(indexPath.getRow()).getFrame().getHeight();
 }
  @Override
  public PFTableViewCell getCellForNextPage(UITableView tableView, NSIndexPath indexPath) {
    final String cellID = "NextPageCell";

    PAPLoadMoreCell cell = (PAPLoadMoreCell) tableView.dequeueReusableCell(cellID);

    if (cell == null) {
      cell = new PAPLoadMoreCell(UITableViewCellStyle.Default, cellID);
      cell.getMainView().setBackgroundColor(UIColor.black());
      cell.setHideSeparatorBottom(true);
      cell.setHideSeparatorTop(true);
    }

    cell.setSelectionStyle(UITableViewCellSelectionStyle.None);

    return cell;
  }
  @Override
  public void didSelectRow(UITableView tableView, NSIndexPath indexPath) {
    if (indexPath.getSection() == 0) {
      switch (indexPath.getRow()) {
        case 0:
          logEventAction();
          break;
        case 1:
          logEventWithParametersAction();
          break;
        case 2:
          logTimedEventAction();
          break;
        case 3:
          logErrorAction();
          break;
        case 4:
          setUserDataAction();
          break;
        case 5:
          setLocationAction();
          break;
        default:
          break;
      }
    } else {
      switch (indexPath.getRow()) {
        case 0:
          break;
        default:
          break;
      }
    }

    tableView.deselectRow(indexPath, true);
  }
  @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;
  }