PFObject 子类未加载 Objective-C

PFObject Subclass Not Loading Objective-C

我 运行 遇到了 PFObject subclass 的麻烦。我已经完成了所有正确的设置(在委托中注册 subclass,设置 class 名称等)。但是由于某种原因,我无法在不崩溃的情况下加载对象,因为它应该被加载。

传递对象

if ([segue.identifier isEqualToString:@"toPostView"])
{
    pbPostViewController *postView = [pbPostViewController new];
    postView = (pbPostViewController *)segue.destinationViewController;
    [postView setPostToLoad:_selectedPost];
}

接收View.h

//  Copyright (c) 2015 Chris Culos. All rights reserved.
//

#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
#import "PALongTextView.h"
#import "pbPost.h"

@interface pbPostViewController : UIViewController

@property (strong, nonatomic) pbPost *postToLoad;

接收View.m

#import "pbPost.h"

@interface pbPostViewController ()

@end

@implementation pbPostViewController

- (void)viewDidLoad {

    pbPost *post = [pbPost postWithObject:_objectToLoad];
    NSLog(@"post: %@", post);


//    _timeStampLabel.text      = post.postTimeStamp;
    _userNameLabel.text       = [post.postOwner valueForKey:@"username"];
    _profileImage.image       = [post.postOwner valueForKey:@"profileImage"];
    _postDescriptionView.text = post.postDescriptionString;
    _bookmarkCounterLabel.text= [NSString stringWithFormat:@"%li bookmarks", post.postBookmarkedArray.count];
    _postContentView.text     = @"POST CONTENT PAGE 123 456 ETC ETC ETC";


    [super viewDidLoad];
    //

pbPost.h

@interface pbPost : PFObject <PFSubclassing>
{

}
@property (nonatomic, retain) NSDate *postTimeStamp;
@property (nonatomic, retain) NSString *postDescriptionString;
@property (nonatomic, retain) NSString *postContentString;
@property (nonatomic, retain) NSString *postBookmarkString;
@property (nonatomic, retain) NSString *postPageCounterString;
@property (nonatomic, retain) NSArray  *postBookmarkedArray;
@property (nonatomic, retain) PFFile   *postOwnerProfileImage;

@property (nonatomic, retain) NSNumber *postFontSize, *totalPages;

@property (nonatomic, retain) PFUser *postOwner;

+ (pbPost *) postWithObject: (PFObject *)object;

pbPost.m

@implementation pbPost

@dynamic postContentString, postBookmarkString, postDescriptionString, postPageCounterString, postTimeStamp, commentTableView, commentButton, bookMarkButton, postOwnerProfileImage, optionsButton, postFontSize, totalPages, postBookmarkedArray, postOwner;

+ (void)load
{
    [self registerSubclass];
}

+ (NSString *)parseClassName
{
    return @"userPosts";
}

+ (pbPost *) postWithObject: (PFObject *)object
{
//    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
//    [dateFormat setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"];
//    [dateFormat setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];

    pbPost *post               = [pbPost postWithObject:object];

    [post fetchInBackgroundWithBlock:^(PFObject *object, NSError *error) {
        if (!error) {
            post.postTimeStamp         = [object valueForKey:@"createdAt"];
            post.postDescriptionString = [object valueForKey:@"titleSummary"];
            post.postFontSize          = [object valueForKey:@"fontSize"];
            post.postContentString     = [object valueForKey:@"postContent"];
            post.totalPages            = [object valueForKey:@"numPages"];
            post.postBookmarkedArray   = [object valueForKey:@"bookmarkedBy"];
            post.postOwner             = [object valueForKey:@"postOwner"];
            post.postOwnerProfileImage = [post.postOwner valueForKey:@"profileImage"];

            NSLog(@"LOAD THE THING!: %@", post);
        }
        else

        {
            NSLog(@"Error Loading Post: %@", error);
        }
    }];




    return post;
}

在这种情况下;我在实现文件中的 + (pbPost *)postWithObject:(PFObject *)object 处得到一个 EXC_BAD_ACCESS

我觉得我在这里遗漏了一些非常简单的东西;它可以是什么?再次提前感谢大家的帮助!这让我困惑了一会儿,我需要一些外部帮助。

由于您要传递 pbPost 对象,因此根本不需要调用 + (pbPost *)postWithObject:(PFObject *)object。要创建 PFObject 子类的新实例,您只需调用:

pbPost *post = [pbPost object];