博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UITableView
阅读量:7183 次
发布时间:2019-06-29

本文共 3020 字,大约阅读时间需要 10 分钟。

hot3.png

- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view, typically from a nib.        self.view.frame = CGRectMake( 0, 0, 375, 667);        UITableView *baseTableView = [[UITableView alloc]initWithFrame:CGRectMake( 0, 30, 375, 667) style:UITableViewStyleGrouped];        baseTableView.delegate = self;    baseTableView.dataSource = self;        [self.view addSubview: baseTableView];}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}//设置有多少个Section 组 默认是1组- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{    return 3;}//设置每个单元格的头信息- (NSString *) tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{    switch ( section) {        case 0:            return @"第一组";            break;        case 1:            return @"第二组";        case 2:            return @"第三组";                    default:            break;    }        return @"";}//设置每个单元格的尾信息- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{    return @"hello!";}//点击某单元格以后响应的事件- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{    NSLog( @"------ %li", [indexPath row] );    return indexPath;}//设置每一组 有多少个单元格- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    return  30;}//绘制Cell 通常为绘制单元格的数据 如 图片 文字 等- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{        //定义一个单元格在缓存里的别名    static NSString *identifer = @"findCell";        //在tableview找可复用的单元格    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: identifer];        if( cell == nil ){        //把某个单元格存入缓存 并用别名存放 方便查找        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier: identifer];    }        cell.frame = CGRectMake( 0, ([indexPath row]+1) * 300, 375, 100);        //单元格索引 从0开始    NSInteger row = [indexPath row];    //设置主标题文字信息    cell.textLabel.text =[NSString stringWithFormat: @"这是第%li行",row+1];    //设置子标题文字信息    cell.detailTextLabel.text= @"没有什么大惊小怪~";    //设置子标题字体、字体大小    cell.detailTextLabel.font = [UIFont fontWithName:@"Arial" size:10];    //选中的样式    cell.selectionStyle = UITableViewCellSelectionStyleDefault;        //设置图片信息    cell.imageView.image = [UIImage imageNamed:@"3.png"];        //cell.accessoryType = UITableViewCellAccessoryNone;//cell没有任何的样式    //cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//cell的右边有一个小箭头,距离右边有十几像素;    //cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;//cell右边有一个蓝色的圆形button;    //cell.accessoryType = UITableViewCellAccessoryCheckmark;//cell右边的形状是对号;    cell.accessoryType = UITableViewCellEditingStyleDelete;        return cell;}//设置每个单元格的行高- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{    return 100;}

 

转载于:https://my.oschina.net/u/2365397/blog/712320

你可能感兴趣的文章
ArcSDE中空间数据的备份与恢复
查看>>
android:onKeyDown
查看>>
go指针的一个小坑
查看>>
VSTO Office二次开发对PowerPoint功能简单测试
查看>>
photoshop快捷键大全
查看>>
Android -- EventBus使用
查看>>
利用gulp搭建本地服务器,并能模拟ajax
查看>>
Java一些八卦集合类
查看>>
linux进程地址空间--vma的基本操作【转】
查看>>
【转】SQLite3的各个函数(全)
查看>>
基于DotNet构件技术的企业级敏捷软件开发平台 AgileEAS.NET - 插件运行容器
查看>>
LintCode: Minimum Path Sum
查看>>
LintCode: Maximum Subarray
查看>>
大数据在金融和贸易中的作用
查看>>
开发者必读 移动端页面优化的10个好方法
查看>>
Nest 为何刚宣布开放 API,就能吸引到重量级盟友?
查看>>
JavaScript之this指针深入详解
查看>>
服务器运行过程中如何进行维护
查看>>
Web前端知识杂乱 如何分清主次和学习优先级?
查看>>
数据驱动的迷思
查看>>