TableViewController.h
#import <UIKit/UIKit.h>
@interface TableViewController : UITableViewController<UITableViewDataSource, UITableViewDelegate>
{
NSArray *products;
}
@end
TableViewController.m
#import "TableViewController.h"
@interface TableViewController ()
@end
@implementation TableViewController
#define ITEM_NAME @"ITEM_NAME"
#define ITEM_PRICE @"ITEM_PRICE"
#define ITEM_PIC @"ITEM_PIC"
#define ITEM_ID @"ITEM_ID"
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
/*
products = [[NSArray alloc] initWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:@"0", ITEM_ID, @"iPAD", ITEM_NAME, @"699$", ITEM_PRICE, @"ipad2.jpg", ITEM_PIC, nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"1", ITEM_ID, @"iMAC", ITEM_NAME, @"1199$", ITEM_PRICE, @"imac.jpg", ITEM_PIC, nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"2", ITEM_ID, @"iPhone", ITEM_NAME, @"699$", ITEM_PRICE, @"iphone.jpg", ITEM_PIC, nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"3", ITEM_ID, @"MacBook", ITEM_NAME, @"699$", ITEM_PRICE, @"macbook.jpg", ITEM_PIC, nil],
[NSDictionary dictionaryWithObjectsAndKeys:@"4", ITEM_ID, @"iPAD Nano", ITEM_NAME, @"149$", ITEM_PRICE, @"nano.jpg", ITEM_PIC, nil],
nil];
*/
products = @[@{ITEM_ID:@"0", ITEM_NAME:@"iPad", ITEM_PRICE:@"699$", ITEM_PIC:@"ipad2.jpg"},
@{ITEM_ID:@"1", ITEM_NAME:@"iMAC", ITEM_PRICE:@"1199$", ITEM_PIC:@"imac.jpg"},
@{ITEM_ID:@"2", ITEM_NAME:@"iPhone", ITEM_PRICE:@"699$", ITEM_PIC:@"iphone.jpg"},
@{ITEM_ID:@"3", ITEM_NAME:@"MacBook", ITEM_PRICE:@"999$", ITEM_PIC:@"macbook.jpg"},
@{ITEM_ID:@"4", ITEM_NAME:@"iPad Nano", ITEM_PRICE:@"149$", ITEM_PIC:@"nano.jpg"}];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#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 [products count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// Configure the cell...
if(cell==nil)
{
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
NSDictionary *productInfo=[products objectAtIndex:indexPath.row];
NSString *name=[productInfo objectForKey:ITEM_NAME];
NSString *price=[productInfo objectForKey:ITEM_PRICE];
NSString *pic=[productInfo objectForKey:ITEM_PIC];
UIImageView *picView=(UIImageView *)[cell viewWithTag:100];
picView.image = [UIImage imageNamed:pic];
UILabel *nameLabel=(UILabel *)[cell viewWithTag:200];
nameLabel.text = name;
UILabel *priceLabel = (UILabel *)[cell viewWithTag:300];
priceLabel.text = price;
return cell;
}
@end
'Programing > IOS' 카테고리의 다른 글
SQLite를 이용한 간단한 DB프로그램 (0) | 2013.09.30 |
---|---|
뷰티 오브 코리아 앱 소스 (0) | 2013.09.16 |
테이블뷰에 웹뷰가 포함된 소스 (0) | 2013.09.11 |
카드 짝 맞추기 게임 (0) | 2013.08.29 |
Slider 및 TextField 및 OnOff 스위치 연습 (0) | 2013.08.26 |