ios - 带有 Parse 对象的 UITableView

标签 ios uitableview parse-platform

我是在 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/

相关文章:

ios - 自定义UICollectionViewCell占用大量内存

ios - 登录 Parse 后如何重新加载 View Controller

node.js - 在亚马逊AWS Elastic beanstalk上安装解析仪表板(或本地?)

ios - Cloud Code 中的 Base64 编码字符串

ios - 不显示所有叠加层,从 kml 文件生成

ios - 在 UITextview 中禁用放大镜,但不禁用 URL 链接和电话号码事件

导航中的 iOS 图像 Item titleview

ios - 如何在 TableViews 中使用 Parse 中的指针关系?

objective-c - UITableView 动画令人头疼

IOS textFieldDidChange 当outlet在其他类中时