parse.com tableview 未加载对象 [英] parse.com tableview not loading objects

查看:55
本文介绍了parse.com tableview 未加载对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 parse.com 加载表视图中的数据,但表视图已加载但没有数据.类名是@"Exibitor",但没有加载任何东西.

I am trying to load data within my table view from parse.com but the table view loads but with no data. The class name is @"Exibitor" but nothing is loading.

@interface DMKViewControllerExhibitors ()

@end

@implementation DMKViewControllerExhibitors



- (id)initWithCoder:(NSCoder *)aCoder {
self = [super initWithCoder:aCoder];
if (self) {
    // Customize the table

    // The className to query on
    self.parseClassName = @"Exibitor";

    // The key of the PFObject to display in the label of the default cell style
    self.textKey = @"objectid";

    // Uncomment the following line to specify the key of a PFFile on the PFObject to display in the imageView of the default cell style
    // self.imageKey = @"image";

    // Whether the built-in pull-to-refresh is enabled
    self.pullToRefreshEnabled = YES;

    // Whether the built-in pagination is enabled
    self.paginationEnabled = YES;

    // The number of objects to show per page
    self.objectsPerPage = 25;

}
return self;

}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
[super viewDidLoad];

// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;

// Uncomment the following line to display an Edit button in the navigation bar for this    view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
}

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[super viewDidAppear:animated];
self.canDisplayBannerAds = YES;

#pragma mark - Parse

- (void)objectsDidLoad:(NSError *)error {
[super objectsDidLoad:error];

// This method is called every time objects are loaded from Parse via the PFQuery
}

- (void)objectsWillLoad {
[super objectsWillLoad];

// This method is called before a PFQuery is fired to get more objects
}


 // Override to customize what kind of query to perform on the class. The default is to       query for
// all objects ordered by createdAt descending.
- (PFQuery *)queryForTable {
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];

// 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.
if ([self.objects count] == 0) {
    query.cachePolicy = kPFCachePolicyCacheThenNetwork;
}

[query orderByAscending:@"name"];


return query;
}



// Override to customize the look of a cell representing an object. The default is to display
// a UITableViewCellStyleDefault style cell with the label being the first key in the    object.
- (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];
}

// Configure the cell
cell.textLabel.text = [object objectForKey:@"text"];
cell.detailTextLabel.text = [NSString stringWithFormat:@"name: %@", [object objectForKey:@"name"]];

return cell;
}

我是解析的新手,无法真正理解为什么它没有加载.我需要它按降序列出所有名称.

I am new to parse and can't really see why it's not loading. I need it to list all names in descending order.

我现在已经把这个 ini 和它抛出一个错误

i have now put this ini and its throwing an error

* 由于未捕获的异常NSInternalInconsistencyException"而终止应用程序,原因:此查询具有未完成的网络连接.你必须等到它完成.* 先抛出调用栈:

- (PFQuery *)queryForTable {
PFQuery *query = [PFQuery queryWithClassName:@"Exibitor"];

[query whereKey:@"Trade" equalTo:@"True"];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {
        // The find succeeded.
        NSLog(@"Successfully retrieved %lu scores.", (unsigned long)objects.count);
        // Do something with the found objects
        for (PFObject *object in objects) {
            NSLog(@"%@", object.objectId);
        }
    } else {
        // Log details of the failure
        NSLog(@"Error: %@ %@", error, [error userInfo]);
    }
}];    return query;
}

推荐答案

这是我的代码的有效副本,我不明白您的应用程序的确切设置,但也许您可以从我的编码并解决了您的问题,祝您好运!

This is a copy of my coding that works, I'm not understanding exactly what your set-up is for your app, but maybe you can take something from my coding and solve your issue, good luck!

- (PFQuery *)queryForTable
{
    PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];

    query.cachePolicy = kPFCachePolicyCacheThenNetwork;

    if (self.canSearch == 0) {
        query = [PFQuery queryWithClassName:self.parseClassName];
    } else {
        query = [PFQuery queryWithClassName:self.parseClassName];

        NSString *searchThis = [searchedBar.text lowercaseString];
        [query whereKey:@"Position" containsString:searchThis];
    }

    [query orderByAscending:@"Position"];

    // If Pull To Refresh is enabled, query against the network by default.
    if (self.pullToRefreshEnabled) {
        query.cachePolicy = kPFCachePolicyNetworkOnly;
    }

    // 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.
    if (self.objects.count == 0) {
        query.cachePolicy = kPFCachePolicyCacheThenNetwork;
    }
    return query;
}

这篇关于parse.com tableview 未加载对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆