Ios 密钥opinionId的类型无效,应为*Opinion,但得到字符串
所以我有我的应用程序,允许用户发送他们的意见,其他用户可以发表评论 我有两张表:Ios 密钥opinionId的类型无效,应为*Opinion,但得到字符串,ios,objective-c,parse-platform,Ios,Objective C,Parse Platform,所以我有我的应用程序,允许用户发送他们的意见,其他用户可以发表评论 我有两张表:意见和评论意见 我的应用程序基于Master/Detail模板: OpinionTimelineTableViewController谁显示用户发布的所有意见 OpinionCommentTableViewController显示所选意见内容和有关所选意见的所有评论的人 因此,我通过prepareForSegue方法成功地在ViewControllers之间传递了所需的数据,一切正常: 在OpinionTimel
意见
和评论意见
我的应用程序基于Master/Detail
模板:
谁显示用户发布的所有意见OpinionTimelineTableViewController
显示所选意见内容和有关所选意见的所有评论的人OpinionCommentTableViewController
prepareForSegue
方法成功地在ViewControllers
之间传递了所需的数据,一切正常:
在OpinionTimelineTableViewController.m
中:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"OpinionComSegue"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
OpinionCommentTableViewController *oPTvc = segue.destinationViewController;
// self.tempObj is a PFObject declared as a property in the .h file (it works)
// self.opinionObjects is an Array declared as a property in the .h file who contains the data I need
self.tempObj = [self.opinionObjects objectAtIndex:indexPath.row];
NSString *opinionContent = [self.tempObj objectForKey:@"content"];
NSString *opinionId = [self.tempObj objectId];
NSDateFormatter *dateForm = [[NSDateFormatter alloc] init];
dateForm.dateFormat = @"dd-MM-yyyy à HH:mm";
NSString *opinionDate = [dateForm stringFromDate:self.tempObj.createdAt];
// "sel" for "selected"
oPTvc.contentSelOpinion = opinionContent;
oPTvc.dateSelOpinion = opinionDate;
oPTvc.selOpinionId = opinionId;
}
}
- (IBAction)sendComment:(id)sender {
PFObject *opinionCom = [PFObject objectWithClassName:@"CommentOpinion"];
opinionCom[@"content"] = self.texteCommToolBar.text;
opinionCom[@"userId"] = [PFUser currentUser];
opinionCom[@"opinionId"] = self.selOpinionId;
[opinionCom saveInBackground];
}
现在,在意见建议TableViewController.m
中:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([[segue identifier] isEqualToString:@"OpinionComSegue"]) {
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
OpinionCommentTableViewController *oPTvc = segue.destinationViewController;
// self.tempObj is a PFObject declared as a property in the .h file (it works)
// self.opinionObjects is an Array declared as a property in the .h file who contains the data I need
self.tempObj = [self.opinionObjects objectAtIndex:indexPath.row];
NSString *opinionContent = [self.tempObj objectForKey:@"content"];
NSString *opinionId = [self.tempObj objectId];
NSDateFormatter *dateForm = [[NSDateFormatter alloc] init];
dateForm.dateFormat = @"dd-MM-yyyy à HH:mm";
NSString *opinionDate = [dateForm stringFromDate:self.tempObj.createdAt];
// "sel" for "selected"
oPTvc.contentSelOpinion = opinionContent;
oPTvc.dateSelOpinion = opinionDate;
oPTvc.selOpinionId = opinionId;
}
}
- (IBAction)sendComment:(id)sender {
PFObject *opinionCom = [PFObject objectWithClassName:@"CommentOpinion"];
opinionCom[@"content"] = self.texteCommToolBar.text;
opinionCom[@"userId"] = [PFUser currentUser];
opinionCom[@"opinionId"] = self.selOpinionId;
[opinionCom saveInBackground];
}
所选意见的objectId
已成功检索,但当我使用模拟器并尝试发布评论时,解析云中没有存储任何内容,我有一条漂亮的错误行:“key opinionId的类型无效,预期*意见,但得到字符串”
有人有办法解决这个问题吗?是不是因为您将opinionId字段的类型设置为指针而不是字符串?是不是因为您认为的指针?这是我发现的唯一合乎逻辑的方法。在文档中,像指针这样的关系的示例并不是很好。无论如何,在我的情况下,我认为……您应该能够在视图控制器之间传递对象,并在新对象中使用它