Advertisement
Guest User

Untitled

a guest
Jan 11th, 2013
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.27 KB | None | 0 0
  1. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  2.  
  3. NSUInteger row = [indexPath row];
  4. NSUInteger count = rows;
  5. UITableViewCell *cell = nil;
  6.  
  7. if (row == count && row > 0) {
  8. // This is the bottom most cell, therefore display the More-Cell
  9. static NSString *postCellId = @"moreCell";
  10.  
  11. cell = [self.tableView dequeueReusableCellWithIdentifier:postCellId];
  12. if (cell == nil) { // it cannot be re-used, so create a new one
  13.  
  14. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:postCellId];
  15.  
  16. loadMore = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, 320, 25)];
  17. displaying = [[UILabel alloc] initWithFrame:CGRectMake(0, 50, 320, 25)];
  18. // now add all sub views such as labels and buttons.
  19. // If the layout is always the same then you may set it here.
  20.  
  21. }
  22. // Now it is either re-used or newly created. However, it carries all the subviews.
  23. // Here set the values. You may set the layout here too, if the layout depends on data.
  24.  
  25.  
  26. loadMore.backgroundColor = [UIColor colorWithRed:255.0 / 255.0 green:255.0 / 255.0 blue:255.0 / 255.0 alpha:1.0];
  27. loadMore.font = [UIFont fontWithName:@"AvenirNext-Bold" size:18.0];
  28. loadMore.textColor = [UIColor colorWithRed:60.0 / 255.0 green:58.0 / 255.0 blue:55.0 / 255.0 alpha:1.0];
  29. loadMore.text = @"Load More...";
  30. loadMore.textAlignment = UITextAlignmentCenter;
  31. [cell.contentView addSubview:loadMore];
  32.  
  33. displaying.backgroundColor = [UIColor colorWithRed:255.0 / 255.0 green:255.0 / 255.0 blue:255.0 / 255.0 alpha:1.0];
  34. displaying.font = [UIFont fontWithName:@"AvenirNext-Bold" size:12.0];
  35. displaying.textColor = [UIColor colorWithRed: 115.0 / 255.0 green: 113.0/ 255.0 blue:112.0 / 255.0 alpha:1.0];
  36. displaying.text = [NSString stringWithFormat:@"Displaying %i Results", rows];
  37. displaying.textAlignment = UITextAlignmentCenter;
  38. [cell.contentView addSubview:displaying];
  39.  
  40. } else {
  41.  
  42.  
  43. // Display a regular Post-Cell
  44. static NSString *postCellId = @"postCell";
  45.  
  46. cell = [self.tableView dequeueReusableCellWithIdentifier:postCellId];
  47. if (cell == nil) { // it cannot be re-used, so create a new one
  48.  
  49. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:postCellId];
  50. // now add all sub views such as labels and buttons.
  51. // If the layout is always the same then you may set it here.
  52.  
  53. thumbimgView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 80, 80)];
  54. businessLabel = [[UILabel alloc] initWithFrame:CGRectMake(103, 10, 207, 25)];
  55. locationLabel = [[UILabel alloc] initWithFrame:CGRectMake(103, 35, 207, 35)];
  56. locimgView = [[UIImageView alloc] initWithFrame:CGRectMake(220, 75, 20, 15)];
  57. distanceLabel = [[UILabel alloc] initWithFrame:CGRectMake(240, 75, 60, 15)];
  58.  
  59. }
  60. // Now it is either re-used or newly created. However, it carries all the subviews.
  61. // Here set the values. You may set the layout here too, if the layout depends on data.
  62.  
  63. dict = [[dictReturn objectForKey:@"listings"] objectAtIndex:0];
  64.  
  65. NSLog(@"%@", dict[@"business"]);
  66.  
  67. businessLabel.backgroundColor = [UIColor colorWithRed:255.0 / 255.0 green:255.0 / 255.0 blue:255.0 / 255.0 alpha:1.0];
  68. businessLabel.font = [UIFont fontWithName:@"AvenirNext-Bold" size:18.0];
  69. businessLabel.textColor = [UIColor colorWithRed:60.0 / 255.0 green:58.0 / 255.0 blue:55.0 / 255.0 alpha:1.0];
  70. businessLabel.text = dict[@"business"];
  71. [cell.contentView addSubview:businessLabel];
  72.  
  73. locationLabel.backgroundColor = [UIColor colorWithRed:255.0 / 255.0 green:255.0 / 255.0 blue:255.0 / 255.0 alpha:1.0];
  74. locationLabel.font = [UIFont fontWithName:@"AvenirNext-Regular" size:14.0];
  75. locationLabel.text = dict[@"location"];
  76. locationLabel.textColor = [UIColor colorWithRed: 115.0 / 255.0 green: 113.0/ 255.0 blue:112.0 / 255.0 alpha:1.0];
  77. locationLabel.numberOfLines = 2;
  78. locationLabel.lineBreakMode = UILineBreakModeTailTruncation;
  79.  
  80. [cell.contentView addSubview:locationLabel];
  81.  
  82. listingLoc = [[CLLocation alloc] initWithLatitude:[dict[@"lat"] doubleValue] longitude:[dict[@"lon"] doubleValue]];
  83.  
  84. AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
  85.  
  86. float kilometers = [appDelegate.currentLoc distanceFromLocation:listingLoc] / 1000;
  87.  
  88. int milesint = kilometers * 0.621371192;
  89.  
  90. NSString *milesOut = [NSString stringWithFormat:@"%i miles", milesint];
  91.  
  92. distanceLabel.backgroundColor = [UIColor colorWithRed:255.0 / 255.0 green:255.0 / 255.0 blue:255.0 / 255.0 alpha:1.0];
  93. distanceLabel.font = [UIFont fontWithName:@"AvenirNext-Regular" size:12.0];
  94. distanceLabel.textColor = [UIColor colorWithRed:128.0 / 255.0 green:128.0 / 255.0 blue:128.0 / 255.0 alpha:1.0];
  95. distanceLabel.text = milesOut;
  96. [cell.contentView addSubview:distanceLabel];
  97.  
  98. NSArray *splitImages = [dict[@"image1"] componentsSeparatedByString:@", "];
  99.  
  100. NSString *imageUrl = [[splitImages objectAtIndex:0] stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
  101.  
  102. icon = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:imageUrl]]];
  103.  
  104. [thumbimgView setContentMode:UIViewContentModeScaleAspectFill];
  105. [thumbimgView setClipsToBounds:YES];
  106.  
  107. thumbimgView.image = icon;
  108. [cell.contentView addSubview:thumbimgView];
  109.  
  110. locimgView.image = [UIImage imageNamed:@"location-icon.png"];
  111. [cell.contentView addSubview:locimgView];
  112.  
  113. cell.textLabel.text = dict[@"business"];
  114. cell.textLabel.hidden = YES;
  115.  
  116. }
  117.  
  118. return cell;
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement