在UITableView部分标题中显示Parse数据库中的日期

时间:2015-12-23 04:35:27

标签: ios uitableview date parse-platform

我正在构建一个从Parse数据库中检索项目并将其插入UITableView的应用程序。在我的Parse数据库中,每个项目都有自己的日期(即电影日期)。现在这是我遇到麻烦的部分:

我想按照自己的日期对项目进行排序,该项目的日期位于节标题中。我还想只显示其日期是从当前日期开始的项目。还请知道我正在使用最新版本的iOS并使用Objective-C。我已经耗尽了其他资源,但还没有找到我需要的东西。任何指导将不胜感激!

现在我在ShowsTableViewController.m中有这个:

我的getShows方法:

-(void)getShows{
    PFQuery *retrieveShows = [PFQuery queryWithClassName:@"shows"];

   [retrieveShows findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError
*error) {
   //NSLog(@"%@", objects);
   if (!error)
   {
       _showsArray = [[NSArray alloc] initWithArray:objects];
   }

   [showsTableView reloadData];

}];
}

这就是我目前填充单元格的方式:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ShowsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"showsCell" forIndexPath:indexPath];

    PFObject *tempObject = [_showsArray objectAtIndex:indexPath.row];

    cell.cellTitle.text = [tempObject objectForKey:@"title];

    return cell;
}

1 个答案:

答案 0 :(得分:0)

根据您的要求,我认为您必须对数据进行排序并将其放入Array。此Array将包含Dictionary列表。每个Dictionary都有两个键(第一个键是title:它的值是你要显示给header的标题,第二个键是data:它的值是seciton中的数组项目

现在你将为它实现UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
     return [self.listData count];
}

对于每个部分,您可以像这样实现:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

   NSArray *data = [[self.listData objectAtIndex:section] objectForKey:@"data"];
}

并显示标题:

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
     return [[self.listData objectAtIndex:section] objectForKey:@"title"];
}

向细胞展示:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
   ShowsTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"showsCell" forIndexPath:indexPath];

   PFObject *tempObject = [[self.listData objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];

   cell.cellTitle.text = [tempObject objectForKey:@"title];

   return cell;
}  

你可以这样做,以达到你想要的。