我有一个表格视图,希望将其存储在parse.com中。
但是,我的表视图中没有任何内容。我已经完成了一些断点和NSLog,发现我的numberOfRowsInSection方法始终返回0。
这是我的代码:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
int num = [_totalDistance count];
NSLog(@"num = %d", num);
return [_totalDistance count];
}
activityTypeArray是从我的viewDidLoad方法中从parse.com收集的数据中填充的,是否可能是问题所在?
这是_totalDistance的填充位置:
- (void)viewDidLoad
{
_activityTypeArray = [NSMutableArray array];
_totalDistance = [NSMutableArray array];
PFQuery *activityQuery = [PFQuery queryWithClassName:@"Activities"];
[activityQuery whereKey:@"triathlete" equalTo:[PFUser currentUser]];
[activityQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
for (PFObject *object in objects) {
;
NSString *activityType = [object objectForKey:@"activityType"];
[_activityTypeArray addObject:activityType];
NSString *totalDistance = [object objectForKey:@"totalDistance"];
[_totalDistance addObject:totalDistance];
NSLog(@" total distance %@", _totalDistance);
int num = [_activityTypeArray count];
NSLog(@"num = %d", num);
}
}
}];
}
谢谢
最佳答案
修改您的代码以重新加载tableView数据。否则,tableView将不知道您要显示的数据。
[activityQuery findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
for (PFObject *object in objects) {
;
NSString *activityType = [object objectForKey:@"activityType"];
[_activityTypeArray addObject:activityType];
NSString *totalDistance = [object objectForKey:@"totalDistance"];
[_totalDistance addObject:totalDistance];
NSLog(@" total distance %@", _totalDistance);
int num = [_activityTypeArray count];
NSLog(@"num = %d", num);
// line added
[self.tableView reloadData];
}
}
}];
关于ios - 表格 View numberOfRowsInSection返回0,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22337611/