Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Parse PFQueryTableViewController for IOS Storyboard

View ViewController.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
#import "ViewController.h"
 
@interface ViewController ()
 
@end
 
@implementation ViewController
 
 
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithClassName:@"groceryList"];
self = [super initWithCoder:aDecoder];
if (self) {
// Custom the table
// The className to query on
self.parseClassName = @"groceryList";
// The key of the PFObject to display in the label of the default cell style
self.textKey = @"item";
// Uncomment the following line to specify the key of a PFFile on the PFObject to display in the imageView of the default cell style
// self.imageKey = @"image";
// 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 = 25;
}
return self;
}
 
 
 
- (void)viewDidLoad
{
[super viewDidLoad];
List = @"<html><body>";
refresh =0;
// Do any additional setup after loading the view, typically from a nib.
}
 
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
 
 
#pragma mark - Parse
 
- (void)objectsDidLoad:(NSError *)error {
[super objectsDidLoad:error];
// This method is called every time objects are loaded from Parse via the PFQuery
}
 
- (void)objectsWillLoad {
[super objectsWillLoad];
// This method is called before a PFQuery is fired to get more objects
}
 
 
// Override to customize what kind of query to perform on the class. The default is to query for
// all objects ordered by createdAt descending.
- (PFQuery *)queryForTable {
PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
counter =[query countObjects];
NSLog(@"%d",counter);
// If no objects are loaded in memory, we look to the cache first to fill the table
// and then subsequently do a query against the network.
if ([self.objects count] == 0) {
query.cachePolicy = kPFCachePolicyCacheThenNetwork;
}
[query orderByDescending:@"createdAt"];
return query;
}
 
 
 
// Override to customize the look of a cell representing an object. The default is to display
// a UITableViewCellStyleDefault style cell with the label being the first key in the object.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
// Configure the cell
cell.textLabel.text = [object objectForKey:@"item"];
//Create the list
if(refresh <counter)
{
NSString *br = @"<br>";
List = [NSString stringWithFormat:@"%@%@%@", List, br, cell.textLabel.text];
NSLog(@"%@",List);
refresh ++;
}
cell.accessoryType =UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
 
[super tableView:tableView didSelectRowAtIndexPath:indexPath];
}
 
 
 
- (IBAction)sendList:(id)sender {
NSDictionary *params = [NSDictionary dictionaryWithObject:List forKey:@"text"];
//NSLog(@"%@",List);
[PFCloud callFunctionInBackground:@"emailGrocery" withParameters:params block:^(id object, NSError *error){} ];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Grocery App"
message:@"Just emailed the Grocery List."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
 
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.