Parse.com - TableView没有加载单元格

时间:2013-05-26 11:04:27

标签: iphone tableview parse-platform cells

我正在尝试显示从Parse.com加载数据的表视图。我没有使用最新版本的框架(因为我项目中的其他模块没有时间更改),这就是为什么我使用“keytoDisplay”并且我没有PFQueryTableViewCell类。

我的问题是关于细胞的加载:我的不加载!我把NSLogs放在我的代码的每一部分,结果就是方法(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath对象:( PFObject *)对象没有被调用。

我不明白为什么......我确认我将我的tableview链接为Delegate和Datasource与我的viewcontroller(我使用Storyboards)。

我是初学者,在发布此处之前我到处寻找答案,但没有成功......我也下载了Parse示例代码,但我没有成功解决我的问题。

非常感谢你!

这是我的代码:

#import "LiveList.h"

@implementation LiveList

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSLog(@"TestViewDidLoad");
    // Custom the table

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

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

    // 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 = 50;




    // 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
{
[self setTableView:nil];
[super viewDidUnload];

// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}

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

NSLog(@"testviewwillappear");

}

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

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

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

- (BOOL)shouldAutorotateToInterfaceOrientation:            (UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
} 

#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];
NSLog(@"test-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:@"LiveList"];

// 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) {
// ** There are other caching options in Parse iOS guide
query.cachePolicy = kPFCachePolicyNetworkElseCache;
}

[query orderByDescending:@"Sport"];

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 {

NSLog(@"TableViewCell");


static NSString *CellIdentifier = @"Cell";

NSLog(@"CellIdentifier");

UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"Cell"];

NSLog(@"CellIdentifier2");

if (cell == nil) {

    NSLog(@"Loop");

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}

// Configure the cell

NSLog(@"ConfigureCell");

cell.textLabel.text = [object objectForKey:@"Sport"];
cell.detailTextLabel.text = [NSString stringWithFormat:@"Lieu: %@", [object objectForKey:@"Lieu"]];

return cell;
}


#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
}

@end

1 个答案:

答案 0 :(得分:0)

在代码中的某处,你应该有以下几点:

[mytableview reloadData];

你需要确保在你从解析中检索的块中,即把它放在最后。这对我有用。它与异步调用有关。

干杯。