简体   繁体   English

PFQueryTableViewController中的多个对象-Parse.com

[英]Multiple objects in PFQueryTableViewController - Parse.com

I'm trying to display two objects or "classNames" into a PFQueryTableViewController . 我试图在PFQueryTableViewController显示两个对象或“ classNames”。 Here is my code so far with only one object. 到目前为止,这是我只有一个对象的代码。 I can't seem to be able to add more than one object. 我似乎无法添加多个对象。

-(id)initWithCoder:(NSCoder *)aDecoder {
    self = [super initWithCoder:aDecoder];
    if (self) {
        // Customize the table

        // The className to query on
        self.className = @"Funny";
        //self.className = @"Story";

        // The key of the PFObject to display in the label of the default cell style
        self.textKey = @"title";

        // Whether the built-in pull-to-refresh is enabled
        self.pullToRefreshEnabled = YES;

        // Whether the built-in pagination is enabled
        self.paginationEnabled = YES;

        // The number of objects to show per page
        self.objectsPerPage = 100;
    }
    return self;
}

Just add more @property s to your view controller. 只需在您的视图控制器中添加更多@property即可。 Make sure to add the necessary ones (className2, textKey2, etc) and to modify the datasource methods of your table view to display the data. 确保添加必要的类(className2,textKey2等),并修改表视图的数据源方法以显示数据。

That being said, it seems strange the the view controller is initiated with initWithCoder . 话虽这么说,用initWithCoder视图控制器似乎很奇怪。 That is usually the method invoked by storyboard for views. 通常是情节提要为视图调用的方法。

I used two object when saving the post. 保存帖子时,我使用了两个对象。 It worked perfectly! 效果很好!

 PFObject *quoteNew = [PFObject objectWithClassName:@"New"];
[quoteNew setObject:[[self attribution] text] forKey:@"by"];
[quoteNew setObject:[[self quoteText] text] forKey:@"quoteText"];
[quoteNew setObject:[[self attributionTitle] text] forKey:@"title"];



[quoteNew saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    if (!error) {
        [self done:self];

    } else {
        [[[UIAlertView alloc] initWithTitle:@"Uh oh. Somthing went wrong"
                                    message:[[error userInfo] objectForKey:@"error"]
                                   delegate:nil
                          cancelButtonTitle:@"Ok"
                          otherButtonTitles: nil] show];
    }

}];


PFObject *quote = [PFObject objectWithClassName:@"Funny"];
[quote setObject:[[self attribution] text] forKey:@"by"];
[quote setObject:[[self quoteText] text] forKey:@"quoteText"];
[quote setObject:[[self attributionTitle] text] forKey:@"title"];


[quote saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    if (!error) {
        [self done:self];

} else {
    [[[UIAlertView alloc] initWithTitle:@"Uh oh. Somthing went wrong"
                                message:[[error userInfo] objectForKey:@"error"]
                               delegate:nil
                      cancelButtonTitle:@"Ok"
                      otherButtonTitles: nil] show];
}

}];

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM