0

一类中的方法:

- (IBAction)createGroup:(id)sender {
    PFObject *message = [PFObject objectWithClassName:@"Messages"];
    [message setObject:self.recipients forKey:@"recipientIds"];
    [message saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (error) {
            NSLog(@"Error %@ %@", error, [error userInfo]);
        }
        else [self performSegueWithIdentifier:@"showDate" sender:self];
    }];
}

然后在另一个:

    else {
            PFQuery *message = [PFQuery queryWithClassName:@"Message"];
                [message getObjectInBackgroundWithId:@"message" block:^(PFObject *message,         NSError *error) {
                [message setObject:file forKey:@"file"];
                [message setObject:fileType forKey:@"fileType"];
                [message setObject:[[PFUser currentUser] objectId] forKey:@"senderId"];
                [message setObject:[[PFUser currentUser] username] forKey:@"senderName"];
                [message saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {

当我运行该应用程序时,没有错误或警告,但它会在访问查询时终止抛出错误。我敢肯定,当我一周前刚刚弹出我的编程樱桃时,我忽略了一些简单的事情。任何帮助将不胜感激。干杯!

4

1 回答 1

0

getObjectInBackgroundWithId:block:需要参数的 Parse 对象ID objectId

如果您只是创建对象,然后尝试将其传递给子视图控制器,那么通过实际的PFObject.

//In your header
@property (nonatomic, strong) PFObject *message;

 //Implementation
 (IBAction)createGroup:(id)sender {
   PFObject *message = [PFObject objectWithClassName:@"Messages"];
   [message setObject:self.recipients forKey:@"recipientIds"];
   [message saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
       if (error) {
           NSLog(@"Error %@ %@", error, [error userInfo]);
       }
       else {
         self.message = message;
         [self performSegueWithIdentifier:@"showDate" sender:self];
       }
   }];
}

您需要prepareForSeque:sender:在视图控制器中实现,然后将 PFObject 传递给子视图控制器:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  if ([segue.identifier isEqualToString:@"showDate"]) {
    YourChildViewController *destViewController = segue.destinationViewController;
    destViewController.message = self.message;
  }
}

然后在您的子视图控制器中:

//In the header, create a property to hold the message object
@property (nonatomic, strong) PFObject *message;

//In the body, you can use self.message
  [self.message setObject:file forKey:@"file"];
  [self.message setObject:fileType forKey:@"fileType"];
  [self.message saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
  ...
于 2013-08-28T00:38:52.467 回答