我遇到了A
子类的问题。我已经通过所有正确的设置(在委托中注册子类,设置类名等)。但由于某种原因,我不能让对象加载而不会在它应该加载的视图中崩溃。
传递对象
PFObject
接收View.h
if ([segue.identifier isEqualToString:@"toPostView"])
{
pbPostViewController *postView = [pbPostViewController new];
postView = (pbPostViewController *)segue.destinationViewController;
[postView setPostToLoad:_selectedPost];
}
接收View.m
// 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;
pbPost.h
#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.m
@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;
在这种情况下;我在实施文件中的@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;
}
处获得EXC_BAD_ACCESS
。
我觉得我在这里缺少一些非常简单的东西;它能是什么?再次感谢大家的帮助!这让我感到困惑了一段时间,我需要得到一些外界的帮助。
答案 0 :(得分:1)
由于您传递的是pbPost对象,因此根本不需要调用+ (pbPost *)postWithObject:(PFObject *)object
。要创建PFObject子类的新实例,只需调用:
pbPost *post = [pbPost object];