kencoder

Table view Cell

May 13th, 2014
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ##Products table view
  2.  
  3. #import "KOProductsTableView.h"
  4. #import "KOProductTableCell.h"
  5. #import "KOProduct.h"
  6.  
  7. @interface KOProductsTableView ()
  8.  
  9. @property (nonatomic) NSMutableArray *products;
  10.  
  11. @end
  12.  
  13. @implementation KOProductsTableView
  14.  
  15. - (void)viewDidLoad
  16. {
  17.     [super viewDidLoad];
  18.      
  19. }
  20.  
  21. -(NSMutableArray *)products
  22. {
  23.     if (_products == nil ) {
  24.        
  25.        
  26.         _products = [NSMutableArray arrayWithArray:@[
  27.                                                        
  28.                                                        [[KOProduct alloc] initWithTitle:@"Poster" imageUrl:@"product01.jpg"],
  29.                                                        [[KOProduct alloc] initWithTitle:@"Square Prints" imageUrl:@"product02.jpg"],
  30.                                                        [[KOProduct alloc] initWithTitle:@"Framed Prints" imageUrl:@"product03.jpg"],
  31.  
  32.                                                        ]];
  33.     }
  34.    
  35.     return _products;
  36. }
  37.  
  38.  
  39. #pragma mark - Table view data source
  40.  
  41.  
  42. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  43. {
  44.     // Return the number of sections.
  45.     return 1;
  46. }
  47.  
  48. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  49. {
  50.     // Return the number of rows in the section.
  51.     return 5;
  52. }
  53.  
  54.  
  55. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  56. {
  57.     KOProductTableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
  58.    
  59.     KOProduct *product = self.products[indexPath.row];
  60.    
  61.     cell.productimage.image = [UIImage imageNamed:product.imageUrl];
  62.     cell.productLabel.text = product.title;
  63.      
  64.     return cell;
  65. }
  66.  
  67.  
  68. -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
  69. {
  70.     NSLog(@"clicked %d",indexPath.row);
  71. }
  72.  
  73. @end
  74.  
  75.  
  76. ##CustomTableViewCell
  77.  
  78. ##Header file
  79.  
  80. #import <UIKit/UIKit.h>
  81.  
  82. @interface KOProductTableCell : UITableViewCell
  83.  
  84.  
  85. @property (weak, nonatomic) IBOutlet UIImageView *productimage;
  86.  
  87. @property (weak, nonatomic) IBOutlet UILabel *productLabel;
  88.  
  89. @end
  90.  
  91.  
  92. ##Implementation fiel
  93.  
  94. #import "KOProductTableCell.h"
  95.  
  96. @implementation KOProductTableCell
  97.  
  98. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  99. {
  100.     self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  101.     if (self) {
  102.         // Initialization code
  103.     }
  104.     return self;
  105. }
  106.  
  107. - (void)awakeFromNib
  108. {
  109.     // Initialization code
  110. }
  111.  
  112. - (void)setSelected:(BOOL)selected animated:(BOOL)animated
  113. {
  114.     [super setSelected:selected animated:animated];
  115.  
  116.     // Configure the view for the selected state
  117. }
  118.  
  119. @end
Advertisement
Add Comment
Please, Sign In to add comment