• UITableView基础知识


    1.继承自UIScrollView

       两种样式都能够分组,只不过是分组显示的效果不同而已

         1.UITableViewStylePlain (列表样式)

           UITableViewStylePlain分组效果,头部标题有悬停效果

         2.UITableViewStyleGrouped (有明显分组效果的样式)

           UITableViewStyleGrouped分组,组与组之间有明显的分隔效果

      创建UITableView

        UITableView * tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];

        [self.view addSubview:tableView];

        

      想要正确的显示出来数据,要保证两点

        1.设置了tableview的协议实现对象

        2.实现datasource协议中必须要实现的方法

        必须实现以下两个协议方法,不实现就报错

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

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

        tableView.dataSource = self;

    --------------------------------

    #pragma mark UITableViewDataSource

      //1.你要让tableview显示多少组数据?

     //可以不实现,默认值是1

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

     
     

     //2.每一组有多少行数据?

     //如果有多组,怎么回答这个问题?

    //必须要实现的协议方法

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

    //3.每一组的每一行,显示什么样的具体数据?

    //UITableViewCell 继承自UIView的特殊视图

    //一个UITableViewCell就代表,UITableView中的一行数据

     //cellForRowAtIndexPath 会被调用多少次呢?

    //必须要实现的方法

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

    //头部

    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

    //尾部

    - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section

    #pragma mark UITableViewDelegate
    //点击哪一行就跳转到哪一行所对应的页面
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
         Item *it = [_dataArray objectAtIndex:indexPath.row];
    
        DetailViewController *detail = [[DetailViewController alloc] init];
        detail.title = it.name;
        [self.navigationController pushViewController:detail animated:YES];
    }

    整体设置,所有行的高度

      tableView.rowHeight = 150;

    设置背景颜色

        tableView.backgroundColor = [UIColor redColor];

        UIImageView * imageView = [[UIImageView alloc] init];

        imageView.image = [UIImage imageNamed:@"img_background.jpg"];

        tableView.backgroundView = imageView;

    设置分割线为no

        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

        

        //自定义给  tableHeaderView添加一个UIView

        UIView * headerView = [[UIView alloc] init];

        headerView.backgroundColor = [UIColor greenColor];

        headerView.frame = CGRectMake(0, 0, 375, 200);

        tableView.tableHeaderView = headerView;

        //自定义给  tableFooterView添加一个UIButton

        tableView.tableFooterView = [UIButton buttonWithType:UIButtonTypeInfoLight];

        


      设置cell的背景颜色

        cell.backgroundColor = [UIColor grayColor];

        UIImageView * backgroundImageView = [[UIImageView  alloc] init];

        backgroundImageView.image = [UIImage imageNamed:@"selected_background"];

        cell.backgroundView = backgroundImageView;

        

      设置选中状态下的背景图片

       cell.selectedBackgroundView = backgroundImageView;

        

       用户提示

          cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

          cell.accessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];


    隐藏状态栏方法,系统自动调用

    - (BOOL)prefersStatusBarHidden

    {

        return YES;

    }

  • 相关阅读:
    保持比例图像缩放简易算法
    ASP.Net中自定义Http处理及应用之HttpModule篇
    用于ASP.NET2.0的进度条控件(实时)
    VS2008SP1下jQuery使用初体验
    qau国庆七天乐——A
    现在的信息科学是泡沫吗?
    dp入门问题
    day09 10 11 12 三天函数内容
    day08文件操作
    day02五大运算符:逻辑运算符、成员运算符、算数、比较、赋值、
  • 原文地址:https://www.cnblogs.com/CLiOS/p/5291651.html
Copyright © 2020-2023  润新知