简体   繁体   中英

PFObject Subclass Not Loading Objective-C

I'm running into some trouble with a PFObject subclass. I've gone thru all of the proper setup (registering the subclass in the delegate, setting the class name, etc). But for some reason I can't get the object to load without crashing it in the view that it's supposed to be loading in.

Passing the Object

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

Receiving 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;

Receiving 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;
}

Under this circumstance; I'm getting an EXC_BAD_ACCESS at + (pbPost *)postWithObject:(PFObject *)object in the implementation file.

I feel like I'm missing something very simple here; what can it be? Thanks in advance for your help again everyone! This has stumped me for a little while and I need to get some outside help.

Since you're passing the pbPost object, you don't need to call the + (pbPost *)postWithObject:(PFObject *)object at all. To create a new instance of your PFObject subclass, you can just call:

pbPost *post = [pbPost object];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM