PFQueryTableView无法正常工作

时间:2014-06-25 20:50:05

标签: ios objective-c xcode parsing uitableview

我正在使用Parse和PFQueryTableViewCotroller开发应用程序,但我无法让它正常工作。这里有一些代码希望你们能找到问题。

ViewController.h

#import <UIKit/UIKit.h>
#import <Parse/Parse.h>

@interface ContainerViewController : PFQueryTableViewController

@end

ViewController.m

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

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

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

    // 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 = 10;
}
return self;
}

- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

- (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 orderByDescending:@"createdAt"];

return query;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
{
static NSString *simpleTableIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}



UILabel *tid = (UILabel*) [cell viewWithTag:1];
tid.text = [object objectForKey:@"Tid"];

UILabel *mandag_fredag = (UILabel*) [cell viewWithTag:2];
mandag_fredag.text = [object objectForKey:@"Mandag_Fredag"];

UILabel *lordag = (UILabel*) [cell viewWithTag:3];
lordag.text = [object objectForKey:@"Lordag"];

UILabel *sondag = (UILabel*) [cell viewWithTag:4];
sondag.text = [object objectForKey:@"Sondag"];

return cell;
}

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

NSLog(@"error: %@", [error localizedDescription]);
}



- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}


@end

我已正确设置标签标签,并将单元标识符设置为@&#34; Cell&#34;。

1 个答案:

答案 0 :(得分:0)

你能够建立这个项目吗?或者你遇到了崩溃?

如果崩溃可能是由于数据模型中其他类的依赖性。

要使其正常工作,请尝试使用queryForTable方法并包含具有dependanices的密钥。

For Instance如果我有一个名为owner的键,它对其他类具有依赖性。您的方法应如下所示:

- (PFQuery *)queryForTable {

PFQuery * query = [PFQuery queryWithClassName:self.parseClassName];

[query includeKey:@“owner”];

返回查询;

}