0

您好,我在从 Parse LocalDataStore 检索 PFObject 子类时遇到问题,我在固定之前已经 NSLogged 对象,它看起来很好,它也成功固定。但是当我在固定对象后去查询对象时,什么都没有出现。

下面是我的代码。有人可以帮我找回我的物品吗?

提前致谢。

Job.h

@interface Job : PFObject<PFSubclassing>

/* Set up all properties that we'll need to record jobs */

// Job Details Properties
@property (retain) NSString *name;
@property (retain) NSString *identifier;
@property (retain) NSString *contact;
@property (retain) NSString *address;
@property (retain) NSString *postcode;

+ (NSString *)parseClassName;

@end

----

Job.m

#import "Job.h"
#import <Parse/Parse.h>
#import <Parse/PFObject+Subclass.h>

@implementation Job

@dynamic name;
@dynamic identifier;
@dynamic contact;
@dynamic address;
@dynamic postcode;

+ (NSString *)parseClassName {

  return @"Jobs";
}


@end

----

MyJobsController.m

#import "MyJobsController.h"
#import "Job.h"

@implementation MyJobsController

- (IBAction)addJob:(id)sender {

    Job *jobOne = [[Job alloc] init];

    jobOne.name = @"Company 001";
    jobOne.contact = @"Dave";
    jobOne.identifier = @"001";

    [jobOne pinInBackgroundWithBlock:^(BOOL succeeded, NSError * _Nullable error) {

        if (succeeded) {

            NSLog(@"Pinned job: %@",job); 

            [self getJobs];           

        }else{

            NSLog(@"Error: %@",error.userInfo);
        }        

 }];
}

- (void)getJobs {

PFQuery *query = [Job query];

[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error) {

      NSLog(@"Found Jobs: %@",objects);

    }else{

      NSLog(@"Error: %@",error.userinfo);

    }
  }]; 
}   

----

MyJobsController.h

#import <UIKit/UIKit.h>

@interface MyJobsController : UIViewController

- (IBAction)addJob:(id)sender;

@end
4

1 回答 1

0

您是否从 parse.com https://parse.com/docs/ios/api/Classes/PFObject.html#//api/name/pinInBackgroundWithBlock看到此 api 信息:据我了解,您必须更改此查询对所有固定对象。 [PFQuery fromLocalDatastore]或者您可以创建一个未提取的指针,[PFObject objectWithoutDataWithClassName:objectId:]然后调用fetchFromLocalDatastore它。https://parse.com/docs/ios/api/Classes/PFQuery.html#//api/name/fromLocalDatastore的参考信息fromLocalDatastore

希望有帮助。

于 2015-11-01T15:05:05.157 回答