//AppDelegate.mではアプリ固有のIDとclientKeyを指定しています。
//storyboardでCellのClassにMyTableCellを指定しています。
- AppDelegate.mではアプリ固有のIDとclientKeyを指定しています。
- storyboardでCellのClassにMyTableCellを指定しています。
#MyTableCellMyTableCell.h
@interface MyTableCell : PFTableViewCell
@property (weak, nonatomic) IBOutlet UILabel *postLabel;
@end
#import <Parse/Parse.h>
@interface MyTableCell : PFTableViewCell
@property (weak, nonatomic) IBOutlet UILabel *postLabel;
@end
#MyPFQueryTableViewControllerMyPFQueryTableViewController.h
\#import <Parse/Parse.h>
@interface MyPFQueryTableViewController : PFQueryTableViewController
@end
#import <UIKit/UIKit.h>
#import <Parse/Parse.h>
@interface MyPFQueryTableViewController : PFQueryTableViewController
@end
#MyPFQueryTableViewControllerMyPFQueryTableViewController.m
#import "MyPFQueryTableViewController.h"\#import "MyTableCell.h"@interface MyPFQueryTableViewController()@end@implementation MyPFQueryTableViewController\-(id)initWithStyle:(UITableViewStyle)style{NSLog(@"%s",\__func__);self = [super initWithStyle:style];if(self){self.parseClassName = @"UserPost";self.pullToRefreshEnabled = YES;self.paginationEnabled = YES;self.objectsPerPage = 25;}return self;}\-(PFQuery *)queryForTable{PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];if(self.pullToRefreshEnabled){query.cachePolicy = kPFCachePolicyNetworkOnly;}if(self.objects.count == 0){query.cachePolicy = kPFCachePolicyCacheThenNetwork;}[query orderByDescending:@"createdAt"];return query;}\-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object{NSLog(@"%s",\__func__);static NSString *CellIdentifier = @"Cell";PFTableViewCell *cell =(PFTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];if(cell == nil){cell = [[PFTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];}MyTableCell *PostCell = nil;PostCell =(MyTableCell *)cell;NSString *PostText = [object objectForKey:@"PostText"];PostCell.postLabel.text = PostText;return cell;}\-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{[super tableView:tableView didSelectRowAtIndexPath:indexPath];}@end#import "MyPFQueryTableViewController.h"
#import "MyTableCell.h"
@interface MyPFQueryTableViewController ()
@end
@implementation MyPFQueryTableViewController
- (id)initWithStyle:(UITableViewStyle)style {
NSLog(@"%s",\__func__);
self = [super initWithStyle:style];
if (self) {
self.parseClassName = @"UserPost";
self.pullToRefreshEnabled = YES;
self.paginationEnabled = YES;
self.objectsPerPage = 25;
}
return self;
}
- (PFQuery *)queryForTable {
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
if (self.pullToRefreshEnabled) {
query.cachePolicy = kPFCachePolicyNetworkOnly;
}
if (self.objects.count == 0) {
query.cachePolicy = kPFCachePolicyCacheThenNetwork;
}
[query orderByDescending:@"createdAt"];
return query;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath object:(PFObject *)object {
NSLog(@"%s",\__func__);
static NSString *CellIdentifier = @"Cell";
PFTableViewCell *cell = (PFTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[PFTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
MyTableCell *PostCell = nil;
PostCell = (MyTableCell *)cell;
NSString *PostText = [object objectForKey:@"PostText"];
PostCell.postLabel.text = PostText;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
}
@end