So I have a UITableView and a Parse query, and the query is able to retrieve the objects from parse. But the TableView is no showing them.
Here is my code I'll explain more below:
- (PFQuery *)query {
NSLog(@"hello");
PFQuery *query = [PFQuery queryWithClassName:@"Posts"];
// If no objects are loaded in memory, we look to the cache first to fill the table
// and then subsequently do a query against the network.
// Query for posts near our current location.
// Get our current location:
//CLLocation *currentLocation = [self.dataSource currentLocationForWallPostsTableViewController:self];
CLLocationAccuracy filterDistance = [[NSUserDefaults standardUserDefaults] doubleForKey:PAWUserDefaultsFilterDistanceKey];
// And set the query to look by location
PFGeoPoint *point = [PFGeoPoint geoPointWithLatitude:40.941984
longitude:-72.88712399999997];
[query whereKey:PAWParsePostLocationKey nearGeoPoint:point withinKilometers:PAWMetersToKilometers(filterDistance)];
[query includeKey:PAWParsePostUserKey];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
// The find succeeded.
NSLog(@"Successfully retrieved %lu users.", (unsigned long)objects.count);
self.myArray = objects;
} else {
// Log details of the failure
NSLog(@"Error: %@ %@", error, [error userInfo]);
}
}];
NSLog(@"work");
return query;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.myArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
NSLog(@"yy");
NSString *kk= [object objectForKey:@"text"];
NSLog(@"%@",kk);
// Configure the cell
cell.textLabel.text = [object objectForKey:@"text"];
return cell;
}
Two things that I have found out that may be causing the issue is:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)sectionis being called before the query, which doesn't make sense to me.And because that is being called before the query the array.count is 0;
So I don't understand why that line would be called before the the query. If you have any suggestions please let me know!
Update This is being called three times, and the second nslog is not being called.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"Fsa");
return self.myArray.count;
NSLog(@"Successfully retrieved %lu .", (unsigned long)self.myArray.count);
}
In my .h
UIViewController <UITableViewDataSource, UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;

self.myArrayto populate the number of rows. That's the issue. That's why you have 0 rows. If no one's able to help you I'll help once I feel a bit better.