Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2014
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.43 KB | None | 0 0
  1. This is my code please help me
  2.  
  3. //
  4. // HomeViewController.m
  5. // Protirup
  6. //
  7. // Created by Alif on 17/08/14.
  8. // Copyright (c) 2014 Alif. All rights reserved.
  9. //
  10.  
  11. #import "HomeViewController.h"
  12.  
  13. @interface HomeViewController ()
  14.  
  15. @end
  16.  
  17. @implementation HomeViewController
  18.  
  19. - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
  20. {
  21. self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
  22. if (self) {
  23. // Custom initialization
  24. }
  25. return self;
  26. }
  27.  
  28. - (id)initWithCoder:(NSCoder *)aDecoder
  29. {
  30. self = [super initWithCoder:aDecoder];
  31. if (self) {
  32. // This table displays items in the Todo class
  33. self.parseClassName = @"Photo";
  34. self.pullToRefreshEnabled = YES;
  35. self.paginationEnabled = YES;
  36. self.objectsPerPage = 3;
  37. }
  38. return self;
  39. }
  40.  
  41. - (void)viewDidLoad
  42. {
  43. [super viewDidLoad];
  44. // Do any additional setup after loading the view.
  45. }
  46.  
  47. - (void)viewWillAppear:(BOOL)animated {
  48. [super viewWillAppear:animated];
  49. [self loadObjects];
  50. }
  51.  
  52. - (void)didReceiveMemoryWarning
  53. {
  54. [super didReceiveMemoryWarning];
  55. // Dispose of any resources that can be recreated.
  56. }
  57.  
  58. #pragma mark - PFQueryTableViewDataSource and Delegates
  59. - (void)objectsDidLoad:(NSError *)error {
  60. [super objectsDidLoad:error];
  61.  
  62. }
  63.  
  64. // return objects in a different indexpath order. in this case we return object based on the section, not row, the default is row
  65.  
  66. - (PFObject *)objectAtIndexPath:(NSIndexPath *)indexPath {
  67. if (indexPath.section < self.objects.count) {
  68. return [self.objects objectAtIndex:indexPath.section];
  69. }
  70. return [self.objects objectAtIndex:indexPath.section];
  71. }
  72.  
  73. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  74. if (section == self.objects.count) {
  75. return nil;
  76. }
  77.  
  78. static NSString *CellIdentifier = @"SectionHeaderCell";
  79. UITableViewCell *sectionHeaderView = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  80.  
  81. PFImageView *profileImageView = (PFImageView *)[sectionHeaderView viewWithTag:1];
  82. UILabel *userNameLabel = (UILabel *)[sectionHeaderView viewWithTag:2];
  83. UILabel *titleLabel = (UILabel *)[sectionHeaderView viewWithTag:3];
  84.  
  85. PFObject *photo = [self.objects objectAtIndex:section];
  86. PFUser *user = [photo objectForKey:@"whoTook"];
  87. PFFile *profilePicture = [user objectForKey:@"profilePicture"];
  88. NSString *title = photo[@"title"];
  89.  
  90. userNameLabel.text = user.username;
  91. titleLabel.text = title;
  92.  
  93. profileImageView.file = profilePicture;
  94. [profileImageView loadInBackground];
  95. return sectionHeaderView;
  96. }
  97.  
  98.  
  99. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  100. NSInteger sections = self.objects.count;
  101. if (self.paginationEnabled && sections>0) {
  102. sections++;
  103. }
  104. return sections;
  105. }
  106.  
  107. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  108. return 1;
  109. }
  110.  
  111. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath object:(PFObject *)object {
  112.  
  113. if (indexPath.section == self.objects.count) {
  114. UITableViewCell *cell = [self tableView:tableView cellForNextPageAtIndexPath:indexPath];
  115. return cell;
  116. }
  117.  
  118. static NSString *CellIdentifier = @"PhotoCell";
  119. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  120. PFImageView *photo = (PFImageView *)[cell viewWithTag:1];
  121. photo.file = object[@"image"];
  122. [photo loadInBackground];
  123. return cell;
  124. }
  125.  
  126.  
  127. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  128. if (section == self.objects.count) {
  129. return 0.0f;
  130. }
  131. return 50.0f;
  132. }
  133.  
  134. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  135. if (indexPath.section == self.objects.count) {
  136. return 50.0f;
  137. }
  138. return 320.0f;
  139.  
  140. }
  141.  
  142.  
  143.  
  144. - (UITableViewCell *)tableView:(UITableView *)tableView cellForNextPageAtIndexPath:(NSIndexPath *)indexPath {
  145. static NSString *CellIdentifier = @"LoadMore";
  146. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
  147. return cell;
  148. }
  149.  
  150.  
  151. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  152. {
  153.  
  154. }
  155.  
  156. - (PFQuery *)queryForTable {
  157. PFQuery *query = [PFQuery queryWithClassName:self.parseClassName];
  158.  
  159. [query includeKey:@"whoTook"];
  160.  
  161. [query orderByDescending:@"createdAt"];
  162.  
  163. return query;
  164.  
  165. }
  166.  
  167.  
  168.  
  169.  
  170. @end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement