• UITableViewController的使用


    如果整个程序界面都只是使用UITableView来搭建,一般需要如下步骤:

    (1)向界面上拖一个UITableView

    (2)设置数据源

    (3)设置代理

    (4)遵守代理协议

     上述过程相对繁琐,为了简化操作,直接使用UITableViewController,但要一定要注意:需要和主控制器类进行关联,还有就是不要把UIViewController当成UITableViewController使用
     
    自定义TableViewCell(在ATDemoCell.m里):

    + (instancetype)cellWithTableView:(UITableView *)tableView

    {

        static NSString *ID = @"cellID";

        ATDemoCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];

        if (cell == nil) {

            cell = [[ATDemoCell alloc] initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:ID];

        }

        return cell;

    }

    - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

    {

        self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

        if (self) {

          // 在此处定义控件

        }

       return self;

    }

     在cellForRowAtIndexPath数据源里调用

    ATDemoCell *cell = [ATDemoCell cellWithTableView:tableView];

    分割线设置

    //设置分割线
    [tableView setSeparatorInset:UIEdgeInsetsMake(0, -67, 0, 0)];
    //
    分割线颜色 self.tableView.separatorColor = [UIColor redColor]; //隐藏分割线 self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    //隐藏多余分割线
    self.tableView.tableFooterView = [[UIView alloc] init];

    取消选中样式

    //取消选中样式
        cell.selectionStyle = UITableViewCellSeparatorStyleNone;

    设置背景色

    // 改变整个tableView的颜色
       tableView.backgroundColor = [UIColor greenColor]

    // 设置选中的背景色 UIView *selectedBackgroundView = [[UIView alloc] init]; selectedBackgroundView.backgroundColor = [UIColor redColor]; cell.selectedBackgroundView = selectedBackgroundView; // 设置默认的背景色 1 cell.backgroundColor = [UIColor blueColor]; // 设置默认的背景色 2 UIView *backgroundView = [[UIView alloc] init]; backgroundView.backgroundColor = [UIColor greenColor]; cell.backgroundView = backgroundView;

    右边指示器显示,比如箭头、打勾,也可以自定义图片等等

    // 显示箭头
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    // 自定义显示,如开关Switch
        cell.accessoryView = [[UISwitch alloc] init];

     设置tableview 不能滚动

     self.tableView.scrollEnabled =NO; 
  • 相关阅读:
    2016年5月27日上午(妙味课堂js基础-3笔记一(事件))
    2016年5月26日晚上(妙味课堂js基础-2笔记四(BOM))
    2016年5月26日晚上(妙味课堂js基础-2笔记三(DOM))
    2016年5月26日晚上(妙味课堂js基础-2笔记二(DOM))
    2016年5月26日下午(妙味课堂js基础-2笔记一(DOM))
    2016年5月26日下午(妙味课堂js基础-1笔记四)
    2016年5月26日下午(妙味课堂js基础-1笔记三)
    2016年5月26日上午(妙味课堂js基础-1笔记二)
    【Django】不知道为什么就是想学一下 01
    【Ubuntu】安装Java和Eclipse
  • 原文地址:https://www.cnblogs.com/xsphehe/p/5614504.html
Copyright © 2020-2023  润新知