Итак, у меня есть UITableView и запрос Parse, и запрос может извлекать объекты из синтаксического анализа. Но TableView не показывает их.UITableView with Parse Query Not Loading
Вот мой код, я объясню более ниже:
- (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;
}
Две вещи, которые я нашел, что может быть причиной проблемы является:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
вызывается перед запросом, что для меня не имеет смысла.И поскольку он вызывается перед запросом, array.count равен 0;
Поэтому я не понимаю, почему эта строка будет вызываться перед запросом. Если у Вас есть предложения, пожалуйста, дайте мне знать!
Обновление Это называется три раза, а второй nslog не вызывается.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSLog(@"Fsa");
return self.myArray.count;
NSLog(@"Successfully retrieved %lu .", (unsigned long)self.myArray.count);
}
В моей .h
UIViewController <UITableViewDataSource, UITableViewDelegate>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
Что вы имеете против ParseQueryTableViewController? – soulshined
@soulshined Ничего не хаха. Я использовал его, но остановился, потому что он не позволял настройки, которые я хотел. – Jack
И ваш вызов этого запроса в viewDidLoad? – soulshined