我是在 iOS 上使用 Parse 的新手。我正在创建一个应该用 Parse 对象填充的 UITableView。这是方法:
- (void)viewDidLoad {
[super viewDidLoad];
[self performSelector:@selector(retrieveFromParse)];
// Do any additional setup after loading the view from its nib.
}
- (void) retrieveFromParse {
PFQuery *retrieveColors = [PFQuery queryWithClassName:@"cadenas"];
[retrieveColors findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
if (!error) {
colorsArray = [[NSArray alloc] initWithArray:objects];
NSLog(@"descargado=%@",colorsArray);
}
[self.tableView reloadData];
}];
}
前面的 NSLog 显示了两个现有的 Parse 对象。
现在是 TableView 方法:
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
// Return the number of rows in the section.
// Usually the number of items in your array (the one that holds your list)
return [colorsArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//Where we configure the cell in each row
static NSString *simpleTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
PFObject *tempObject = [colorsArray objectAtIndex:indexPath.row];
NSLog(@"CADNA =%@:",[colorsArray objectAtIndex:indexPath.row]);
cell.textLabel.text = [tempObject objectForKey:@"chain_name"];;
return cell;
}
最后一个 NSLog 没有被调用,因此 UITableView 是空的。
我做错了什么?
谢谢。
最佳答案
我的猜测是查询时间与构建 View 。而不是...
- (void)viewDidLoad {
[super viewDidLoad];
// remove this
[self performSelector:@selector(retrieveFromParse)];
...做这个...
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self retrieveFromParse];
}
通过这种方式,我们可以确定地知道在查找完成后所有 View 都已构建并准备就绪。
关于ios - 带有 Parse 对象的 UITableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28549193/