方法:
- (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) {
当我运行应用程序时,没有错误或警告,但它会在访问查询时终止抛出错误。我确信这是一件很简单的事情,因为我刚刚在一周前弹出了我的编程樱桃。任何帮助将不胜感激。干杯!
答案 0 :(得分:0)
getObjectInBackgroundWithId:block:
需要objectId
参数的Parse对象ID。
如果您只是创建对象然后尝试将其传递给子视图控制器,那么最好通过实际的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) {
...