【问题标题】:parse.com tableview not loading objectsparse.com tableview 不加载对象
【发布时间】:2014-07-18 13:55:56
【问题描述】:

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

@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;
}

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

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

* 由于未捕获的异常“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;
}

【问题讨论】:

    标签: ios xcode uitableview parse-platform


    【解决方案1】:

    也许您只是错过了将此代码粘贴到问题中,但需要执行查询。我们需要在某个地方这样做...

    PFQuery *query = [self queryForTable];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {
            // have your tableView reloadData (you need an outlet to do this)
        } else {
            // Log details of the failure
            NSLog(@"%@", error);
        }
    }];
    

    【讨论】:

    • 看看我的回答是如何开始的,“也许你错过了粘贴......”。我想你错过了粘贴。从错误来看,似乎已经有一个 queryForTable 方法的调用者。通过将我的代码添加到该方法中,您将调用它两次。
    • 在所有文件中搜索 findObjectsInBackgroundWithBlock。如果它被调用两次,就会产生你看到的错误。
    • 只有一个 [query whereKey:@"Trade" equalTo:@"True"]; [查询 findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    【解决方案2】:

    这是我的有效编码的副本,我不完全了解您的应用程序设置是什么,但也许您可以从我的编码中获取一些东西并解决您的问题,祝您好运!

    - (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;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-02
      • 1970-01-01
      • 1970-01-01
      • 2017-11-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多