2013-08-04 34 views
1

我試圖將兩個對象或「classNames」顯示爲PFQueryTableViewController。這是我的代碼到目前爲止只有一個對象。我似乎無法添加多個對象。PFQueryTableViewController中的多個對象 - Parse.com

-(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; 
} 

回答

0

只需將更多@property s添加到您的視圖控制器。確保添加必要的(className2,textKey2等),並修改表視圖的數據源方法以顯示數據。

這就是說,看起來很奇怪的視圖控制器是由initWithCoder啓動的。這通常是故事板爲視圖調用的方法。

+0

我會在哪裏做呢?在框架工作(PFQueryTableViewController.h)?你有更好的方法,而不是initWithCoder?謝謝。 – user2649903

0

保存帖子時使用了兩個對象。它非常完美!

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]; 
} 

}]; 

}

相關問題