Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- This is my code please help me
- //
- // HomeViewController.m
- // Protirup
- //
- // Created by Alif on 17/08/14.
- // Copyright (c) 2014 Alif. All rights reserved.
- //
- #import "HomeViewController.h"
- @interface HomeViewController ()
- @end
- @implementation HomeViewController
- - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
- {
- self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
- if (self) {
- // Custom initialization
- }
- return self;
- }
- - (id)initWithCoder:(NSCoder *)aDecoder
- {
- self = [super initWithCoder:aDecoder];
- if (self) {
- // This table displays items in the Todo class
- self.parseClassName = @"Photo";
- self.pullToRefreshEnabled = YES;
- self.paginationEnabled = YES;
- self.objectsPerPage = 3;
- }
- return self;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [self loadObjects];
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- // Dispose of any resources that can be recreated.
- }
- #pragma mark - PFQueryTableViewDataSource and Delegates
- - (void)objectsDidLoad:(NSError *)error {
- [super objectsDidLoad:error];
- }
- // return objects in a different indexpath order. in this case we return object based on the section, not row, the default is row
- - (PFObject *)objectAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.section < self.objects.count) {
- return [self.objects objectAtIndex:indexPath.section];
- }
- return [self.objects objectAtIndex:indexPath.section];
- }
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
- if (section == self.objects.count) {
- return nil;
- }
- static NSString *CellIdentifier = @"SectionHeaderCell";
- UITableViewCell *sectionHeaderView = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- PFImageView *profileImageView = (PFImageView *)[sectionHeaderView viewWithTag:1];
- UILabel *userNameLabel = (UILabel *)[sectionHeaderView viewWithTag:2];
- UILabel *titleLabel = (UILabel *)[sectionHeaderView viewWithTag:3];
- PFObject *photo = [self.objects objectAtIndex:section];
- PFUser *user = [photo objectForKey:@"whoTook"];
- PFFile *profilePicture = [user objectForKey:@"profilePicture"];
- NSString *title = photo[@"title"];
- userNameLabel.text = user.username;
- titleLabel.text = title;
- profileImageView.file = profilePicture;
- [profileImageView loadInBackground];
- return sectionHeaderView;
- }
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
- NSInteger sections = self.objects.count;
- if (self.paginationEnabled && sections>0) {
- sections++;
- }
- return sections;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
- return 1;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
- if (indexPath.section == self.objects.count) {
- UITableViewCell *cell = [self tableView:tableView cellForNextPageAtIndexPath:indexPath];
- return cell;
- }
- static NSString *CellIdentifier = @"PhotoCell";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- PFImageView *photo = (PFImageView *)[cell viewWithTag:1];
- photo.file = object[@"image"];
- [photo loadInBackground];
- return cell;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
- if (section == self.objects.count) {
- return 0.0f;
- }
- return 50.0f;
- }
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- if (indexPath.section == self.objects.count) {
- return 50.0f;
- }
- return 320.0f;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForNextPageAtIndexPath:(NSIndexPath *)indexPath {
- static NSString *CellIdentifier = @"LoadMore";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
- return cell;
- }
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- }
- - (PFQuery *)queryForTable {
- PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
- [query includeKey:@"whoTook"];
- [query orderByDescending:@"createdAt"];
- return query;
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement