IOS UITableview

  • 表视图由头部,尾部视图,中间由一连串单元格视图组成。
  • 表视图头部由tableHeaderView属性设置,尾部视图通过tableFooterView属性设置。
  • 分组表格由一连串section视图组成,每个section又包含一个连续的单元格
  • 每个section视图也有头部视图和尾部视图,通过委托方法设置。


1. .h 文件要声明协议

<UITableViewDataSource>


2.再.h文件中创建数据集合

@property (nonatomic,retain)NSArray *listArray;//tableView的数据集合


3..h中声明变量

@private

   UITableView *_tableView;


4.实例化变量

_tableView = [[UITableViewalloc] initWithFrame:self.view.boundsstyle:UITableViewStylePlain];

    

    //得到字体所有样式

   self.listArray = [UIFontfamilyNames];

    

    //实现数据源方法

    _tableView.dataSource =self;

    [self.viewaddSubview:_tableView];


5.覆盖delegate方法

#pragma mark - tableView 的数据源方法

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

{

   return [self.listArraycount];

}


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

{

   static NSString *cellIdentifier =@"cell";

   UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    

   if (cell == nil) {

        cell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:cellIdentifier];

    }

    

   NSString *fontName = self.listArray[indexPath.row];

    cell.textLabel.text = fontName;

    cell.textLabel.font = [UIFontfontWithName:fontName size:14];

    

   return cell;

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值