IOS---自定义单元格

1、修改根试图

点击view controller scene下边,选中scene,按del键即可删除;

从控件库中拖拽一个Tab View Controller到设计界面;

然后右边的属性检查器中,选中View Controller---> is  Initial View Controller复选框;

如下图:

2、设置单元格

 

 

 

设置类

设置可重用单元格标示符

3、设置自定义单元格类CustomCell

创建之后,如下:

设置单元格的类(绑定)

单元格中的label   image  输出关联到 CustomCell.h中:

ViewController.m中,引入头文件:

#import "ViewController.h"

#import "CustomCell.h"

#define cellIdentifier  @"CellIdentifier"

@interface ViewController ()

@property (nonatomic, strong) NSArray *listTeams;

@end

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    

    

    NSBundle *bundle = [NSBundle mainBundle];

    NSString *plistPath = [bundle pathForResource:@"team"

                                           ofType:@"plist"];

    //获取属性列表文件中的全部数据

    self.listTeams = [[NSArray alloc] initWithContentsOfFile:plistPath];

}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

#pragma mark --UITableViewDataSource 协议方法

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

    return [self.listTeams count];

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

      CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];

    NSUInteger row = [indexPath row];

    NSDictionary *rowDict = self.listTeams[row];

    cell.myLabel.text = rowDict[@"name"];

    NSString *imageFile = rowDict[@"image"];

    NSString *imagePath = [[NSString alloc] initWithFormat:@"%@.png", imageFile];

    cell.myImageView.image = [UIImage imageNamed:imagePath];

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    return cell;

}@end

 

参考:《IOS开发指南》

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值