UITableView---初始化
来源:互联网 发布:易安卓播放器源码 编辑:程序博客网 时间:2024/04/30 04:33
#import "ViewController.h"
@interface ViewController ()
{
NSArray * _array;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
//加载数据
[self_loadData];
//初始化
UITableView * tableView=[[UITableViewalloc]initWithFrame:CGRectMake(0,20, self.view.frame.size.width,self.view.frame.size.height-20)style:UITableViewStylePlain];
//tableView有两个代理
tableView.dataSource=self; //1 专门加载数据
tableView.delegate =self; //2 监听---实现某种方法
tableView.rowHeight=100; //设置每一行的高度
//tableView.estimatedRowHeight=79;
//加载到视图
[self.viewaddSubview:tableView];
}
- (void) _loadData
{
_array=[UIFontfamilyNames];
}
// <UITableViewDataSource>协议 必须 实现的 两个方法
#pragma mark - 1.返回当前行数
//返回当前tableView的行数 ---用来控制行数多少
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return _array.count;
}
#pragma mark - 2.将数据放到单元格
//根据行数,new出新的单元格放到当前行
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//返回值是 UITableViewCell *类型,所以初始化一个 UITableViewCell * 类型的对象
UITableViewCell * cell=[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:@"mytable"];
NSLog(@"Hello%ld",indexPath.row); //调用次数
cell.textLabel.text=_array[indexPath.row]; //cell中存放的内容
cell.textLabel.font=[UIFontfontWithName:_array[indexPath.row]size:16]; //设置内容的字体大小
return cell;
}
@end
- UITableView---初始化
- UITableview自定义代码初始化
- UITableView的初始化(以下拉菜单式为例)
- UITableView
- UITableView
- UITableView
- UITableView
- UITableView
- UITableView
- UITableView
- UITableView
- UITableview
- UITableView
- UITableView
- UITableView
- UITableView
- UITableView,
- UITableView
- 第八周【项目1-实现复数类中的运算符重载】
- 疯狂JAVA之学习笔记(5)----------注释
- 基于protobuf的RPC实现
- shell条件判断之test命令实例详解
- 树分治(hdu5016-2014西安现场赛)
- UITableView---初始化
- 深入剖析jsp的工作原理
- SQL with as 的用法 以及递归函数的写法
- 神经网络与机器学习导言笔记——网络结构与知识表示
- 清除float常用方法(:after和clear:both)
- Unity3D修改脚本模板
- String,StringBuilder,String Buffer的一点小结
- GRE、PPTP、L2TP隧道协议
- NYOJ 58 最小步数【bfs】