Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##Products table view
- #import "KOProductsTableView.h"
- #import "KOProductTableCell.h"
- #import "KOProduct.h"
- @interface KOProductsTableView ()
- @property (nonatomic) NSMutableArray *products;
- @end
- @implementation KOProductsTableView
- - (void)viewDidLoad
- {
- [super viewDidLoad];
- }
- -(NSMutableArray *)products
- {
- if (_products == nil ) {
- _products = [NSMutableArray arrayWithArray:@[
- [[KOProduct alloc] initWithTitle:@"Poster" imageUrl:@"product01.jpg"],
- [[KOProduct alloc] initWithTitle:@"Square Prints" imageUrl:@"product02.jpg"],
- [[KOProduct alloc] initWithTitle:@"Framed Prints" imageUrl:@"product03.jpg"],
- ]];
- }
- return _products;
- }
- #pragma mark - Table view data source
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
- {
- // Return the number of sections.
- return 1;
- }
- - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- {
- // Return the number of rows in the section.
- return 5;
- }
- - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- {
- KOProductTableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
- KOProduct *product = self.products[indexPath.row];
- cell.productimage.image = [UIImage imageNamed:product.imageUrl];
- cell.productLabel.text = product.title;
- return cell;
- }
- -(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSLog(@"clicked %d",indexPath.row);
- }
- @end
- ##CustomTableViewCell
- ##Header file
- #import <UIKit/UIKit.h>
- @interface KOProductTableCell : UITableViewCell
- @property (weak, nonatomic) IBOutlet UIImageView *productimage;
- @property (weak, nonatomic) IBOutlet UILabel *productLabel;
- @end
- ##Implementation fiel
- #import "KOProductTableCell.h"
- @implementation KOProductTableCell
- - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
- {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- // Initialization code
- }
- return self;
- }
- - (void)awakeFromNib
- {
- // Initialization code
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated
- {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- @end
Advertisement
Add Comment
Please, Sign In to add comment