PFQueryTableViewController 错误 [英] PFQueryTableViewController error

查看:17
本文介绍了PFQueryTableViewController 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在在线学习使用 Parse 作为后端创建照片共享应用程序的教程.我已经运行了两次教程,两次都是从头开始创建应用程序,但仍然在同一位置发生相同的错误.我已经四处寻找解决方案,但仍然没有运气.

I'm following a tutorial online for creating a photo sharing app using Parse as a backend. I've run through the tutorial twice, creating the app from scratch both times, and still the same error occurs at the same spot. I've looked high and low for a solution and still no luck.

我正在使用 PFQueryTableViewController,并且我的内容被加载到多个部分而不是行中.每个部分在部分标题中显示 PFUser 详细信息,并且每个部分只有一行,显示该用户加载的图像.在每个页面的末尾(我启用了分页,一次加载 3 个对象)有一个加载更多"按钮,可以在单击时将接下来的 3 个对象加载到表格视图中.但是,当我单击此按钮时,我的应用程序崩溃并显示此错误:

I'm using a PFQueryTableViewController, and my content is being loaded in multiple sections instead of rows. Each section displays PFUser details in the section header, and each section has only one row, which displays the image loaded by that user. At the end of each page (I have pagination enabled, loading 3 objects at a time) there is a "Load more" button to load the next 3 objects into the table view when clicked. However, when I click this button, my app crashes and presents this error:

断言失败 -[UITableView _endCellAnimationsWithContext:],/SourceCache/UIKit_Sim/UIKit-2935.137/UITableView.m:11142014-07-28 01:50:37.368 SampleCamApp[25686:60b] 由于未捕获的异常NSInternalInconsistencyException"而终止应用程序,原因:尝试从更新前仅包含 1 行的第 0 节中删除第 3 行"

这是我的代码:

#import "HomeViewController.h"

@interface HomeViewController ()

@end

@implementation HomeViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super initWithCoder:aDecoder];
    if (self) {
        // This table displays items in the Todo class
        self.parseClassName = @"Photo";
        self.pullToRefreshEnabled = YES;
        self.paginationEnabled = YES;
        self.objectsPerPage = 3;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

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

    [self loadObjects];
}

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

#pragma mark - PFQueryTableViewDataSource and Delegates
- (void)objectsDidLoad:(NSError *)error
{
    [super objectsDidLoad:error];

}

// return objects in a different indexpath order. in this case we return object based on the section, not row, the default is row
- (PFObject *)objectAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section < self.objects.count)
    {
        return  [self.objects objectAtIndex:indexPath.section];
    }
    else
    {
        return nil;
    }
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if(section == self.objects.count)
    {
        return nil;
    }
    static NSString *CellIdentifier = @"SectionHeaderCell";
    UITableViewCell *sectionHeaderView = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    PFImageView *profileImageView = (PFImageView *)[sectionHeaderView viewWithTag:1];
    UILabel *userNameLabel = (UILabel *)[sectionHeaderView viewWithTag:2];
    UILabel *titleLabel = (UILabel *)[sectionHeaderView viewWithTag:3];

    PFObject *photo = [self.objects objectAtIndex:section];
    PFUser *user = [photo objectForKey:@"whoTook"];
    PFFile *profilePicture = [user objectForKey:@"profilePicture"];
    NSString *title = photo[@"title"];

    userNameLabel.text = user.username;
    titleLabel.text = title;

    profileImageView.file = profilePicture;
    [profileImageView loadInBackground];

    return sectionHeaderView;
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    NSInteger sections = self.objects.count;

    if(self.paginationEnabled && sections >0)
    {
        sections++;
    }
    return sections;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object
{
    if(indexPath.section == self.objects.count)
    {
        UITableViewCell *cell = [self tableView:tableView cellForNextPageAtIndexPath:indexPath];
        return cell;
    }

    static NSString *CellIdentifier = @"PhotoCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    PFImageView *photo = (PFImageView *)[cell viewWithTag:1];
    photo.file = object[@"image"];
    [photo loadInBackground];

    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if(section == self.objects.count)
    {
        return 0.0f;
    }
    return 50.0f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section == self.objects.count)
    {
        return 50.0f;
    }
    return 320.0f;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForNextPageAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"LoadMoreCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section == self.objects.count && self.paginationEnabled)
    {
        [self loadNextPage];
    }
}

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

    [query includeKey:@"whoTook"];

    [query orderByDescending:@"createdAt"];

    return query;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end

当我运行我的应用程序时,所有内容都被正确加载,包括图像、文本等......只有当我点击按钮时才会出现问题.在这一点上,我对 iOS 开发非常熟悉,但是,我对 Parse 还很陌生,这是我第一次使用 PFQueryTableViewController.请让我知道我是否在错误地实施某些东西,否则我只需要解决一个常规的 UITableViewController 来实现这一点.

When I run my app, all content gets loaded correctly, including images, text, etc... Its only when I click the button that the trouble starts. I'm pretty cozy with iOS development at this point, however, I'm fairly new to Parse, and this is the first time I've used a PFQueryTableViewController. Please let me know if I'm implementing something incorrectly, otherwise I'll just have to work around a regular UITableViewController to make this happen.

推荐答案

一种解决方法是调整 ParseUI 中提供的自定义 PFQueryTableViewController.h 文件.

one workaround is to tweak the custom PFQueryTableViewController.h file provided in ParseUI.

只需在 HomeViewController.m 中包含以下内容即可覆盖 Parse 提供的类似方法(如果不存在,请将其添加到 ParseUI.Framework>Headers 下的 PFQueryTableViewController.h将此添加到 h.:- (NSIndexPath *)_indexPathForPaginationCell;

Simply include the following in your HomeViewController.m to override the Parse provided similar method(If it doesn't exist , add it to the PFQueryTableViewController.h under ParseUI.Framework>Headers Add this to the h.: - (NSIndexPath *)_indexPathForPaginationCell;

在您的 .m 文件中调用以下代码:

Call the code below in your .m file:

- (NSIndexPath *)_indexPathForPaginationCell {

return [NSIndexPath indexPathForRow:0inSection:[self.objectscount]];

return [NSIndexPath indexPathForRow:0inSection:[self.objectscount]];

}

感谢一位名叫 Axel Wittmann 的先生们.

Credit goes to a gentlemen by the name of Axel Wittmann .

这篇关于PFQueryTableViewController 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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