zoukankan      html  css  js  c++  java
  • UITableView的简单应用介绍

    创建一个tableView视图,然后把这个视图界面添加到主界面上。

    _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 20, [UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.height-20) style:UITableViewStylePlain];

    每一个表视图都是需要delegate委托和datasoure数据源的

        _tableView.delegate = self;
        _tableView.dataSource = self;
    


    通过下面的方法来设置表视图的边界

        UIEdgeInsets contentInset = _tableView.contentInset;
        contentInset.top = -20;
        [_tableView setContentInset:contentInset];

    表视图的都需要cell,一般都是自定义的设置一个cell来实现的。

    创建相应地cell.xib与类中的Outlet接口关联起来。如果cell里面的属性需要和外界联系,则将其set在接口文件中。


                                                                    

    有时候,cell文件中需要实现自定义的button编写:

     UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setTitle:@"" forState:UIControlStateNormal];
        UIImage *arrowImage = [UIImage imageNamed:@"rightArrow"];
        [btn setBackgroundImage:arrowImage forState:UIControlStateNormal];
        btn.frame = CGRectMake(300, 60, arrowImage.size.width, arrowImage.size.height);
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];


    table中有一个TableHeaderView的属性,可以在这个属性中自定义一些view。下面是自定义一个滚动视图到TableHeaderView。

    注意:这个TableHeaderView虽然是表视图中的第一个cell,但是一般我们不将他算到delegate和datasource中。

    //    添加一个滚动试图在表示图的第一个cell上面
        [self setScrollView];//添加一个滚动视图,详细代码不在这个说明了。
    
        [_tableView setTableHeaderView:_main_scrollView];

    将一个视图移动到view视图界面的最底层,可以用下面的方法:

    [self.view sendSubviewToBack:_tableView];


    下面是tableView中一些常用的嵌入方法:

    //点击tableView中的cell时,将调用这个方法
    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    
    //用来获取分区的行数
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    
    //用来设定行高
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    
    //返回一个TableViewCell类型的例子,作为tableView中的cell
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath


    在tableView中实现向左滑动->点按delete操作

    //实现删除操作
    - (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return UITableViewCellEditingStyleDelete;
    }
    
    -(void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
    {
        if (editingStyle == UITableViewCellEditingStyleDelete) {
    <span style="white-space:pre">	</span>//在这里开始编写删除操作代码
        }
    }


  • 相关阅读:
    使用Power Query从Web页面获取图像到Power BI报告中
    视频 |【2019】Power BI 8月产品功能更新讲解
    【2019】微软Power BI 每月功能更新系列——Power BI 8月版本功能完整解读
    视频 |【2019】Power BI 7月产品功能更新讲解
    2019 年 BI 平台 Top 14
    2016 黑客必备的Android应用都有哪些?
    J2EE完全手册(二)
    JavaBean ,Enterprise Bean(EJB), 三种Bean, 以及POJO
    J2EE完全手册(一)
    J2EE简介
  • 原文地址:https://www.cnblogs.com/AbeDay/p/5026959.html
Copyright © 2011-2022 走看看