table范例

本文介绍了一个iOS平台上的菜品展示应用程序开发过程,该应用使用Core Data进行数据管理,并实现了UITableView来展示菜品信息,包括菜品名称、配料、作者及图片。
 1 - (void)viewDidLoad
 2 {
 3     [super viewDidLoad];
 4     // Do any additional setup after loading the view.
 5     //创建一个模拟从coreData创建的数据
 6     NSMutableArray *data = [NSMutableArray arrayWithObjects:
 7                             [NSDictionary dictionaryWithObjectsAndKeys:@"宫保鸡丁", @"name", @"鸡丁、辣椒", @"Element", @"小鸟依人", @"author", @"pic01", @"image", nil],
 8                             [NSDictionary dictionaryWithObjectsAndKeys:@"辣子鸡块", @"name", @"鸡丁、辣椒", @"Element", @"小鸟依人", @"author", @"pic01", @"image", nil],
 9                             [NSDictionary dictionaryWithObjectsAndKeys:@"小炒肉丝", @"name", @"鸡丁、辣椒", @"Element", @"小鸟依人", @"author", @"pic01", @"image", nil], nil];
10     //全局的数据对象
11     cookData = data;
12 }
13 
14 //table内容的列数
15 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
16     return [cookData count];
17 }
18 
19 //table cell的创建
20 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
21     static NSString *cookTableId = @"cookTable";
22     //从内存池中取出已存在cell
23     mxdCookCell *cell = (mxdCookCell *)[tableView dequeueReusableCellWithIdentifier:cookTableId];
24     //如果不存在则创建
25     if (cell == nil) {
26         //通过自定义的cookCell.xib模板创建cell
27         NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"cookCell" owner:self options:nil];
28         cell = [nib objectAtIndex:0];
29     }
30     //数据填充
31     NSDictionary *cookCell = [cookData objectAtIndex:indexPath.row];
32     cell.cookName.text = [cookCell objectForKey:@"name"];
33     cell.cookElement.text = [cookCell objectForKey:@"Element"];
34     cell.cookAuthor.text = [cookCell objectForKey:@"author"];
35     //查询image所在路径
36     NSString *path = [[NSBundle mainBundle] pathForResource:[cookCell objectForKey:@"image"] ofType:@"jpg"];
37     cell.cookImage.image = [UIImage imageWithContentsOfFile:path];
38     return cell;
39 }
40 
41 //设置cell高度
42 - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
43     return 72;
44 }

 

转载于:https://www.cnblogs.com/cat3/archive/2013/03/23/2977471.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值