zoukankan      html  css  js  c++  java
  • Storyboard之Tableview

    注册cell常用方法:

    设置全局变量static NSString *identifier = @"videoIdentifier";

    1.viewDidLoad注册cell

    [self.tableView registerNib:[UINib nibWithNibName:@"VideoCell" bundle:nil] forCellReuseIdentifier:identifier];

    2.cellforRow中关联cell

    VideoCell *cell=[tableView dequeueReusableCellWithIdentifier:identifier];

    推荐使用封装方法:

    将cell注册方法封装在BaseTableViewCell基类里(新建一个tableviewcell类)

    1.BaseTableViewCell.h 

    + (instancetype)cellWithTableView:(UITableView *)tableView;

    2.BaseTableViewCell.m 实现

    + (instancetype)cellWithTableView:(UITableView *)tableView{

        NSString *className = NSStringFromClass([self class]);

        TPBaseTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:className];

        if (!cell) {

            cell = [[NSBundle mainBundle] loadNibNamed:className owner:nil options:nil].firstObject;

            cell.selectionStyle = UITableViewCellSelectionStyleNone;

        }

        return cell;

    }

    3.引用时候:将自定义的cell基类更改为BaseTableViewCell如:

    @interface TPChatSettingsTableViewCel : TPBaseTableViewCell

    只需要在cellforrow中关联cell即可

    TPChatSettingsTableViewCell *cell = [TPChatSettingsTableViewCell cellWithTableView:tableView];

     同理注册view

    .h

    + (instancetype)createViewFromNib;

     + (instancetype)createViewFromNibName:(NSString *)nibName;

    .m

    + (instancetype)createViewFromNibName:(NSString *)nibName

    {

        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:nil];

        return [nib objectAtIndex:0];

    }

     + (instancetype)createViewFromNib

    {

        return [self createViewFromNibName:NSStringFromClass(self.class)];

    }

    引用时候

     self.alertCoinView = [TPAlertPetCoinView createViewFromNib];

  • 相关阅读:
    blender+threejs
    170112、solr从服务器配置整合到项目实战
    170111、MapperScannerConfigurer处理过程源码分析
    170110、Spring 事物机制总结
    170109、JSONP是什么
    170106、用9种办法解决 JS 闭包经典面试题之 for 循环取 i
    170105、MySQL 性能优化的最佳 20+ 条经验
    170104、js内置对象与原生对象
    170103、Redis官方集群方案 Redis Cluster
    161230、利用代理中间件实现大规模Redis集群
  • 原文地址:https://www.cnblogs.com/jiangxue-iOS/p/7602740.html
Copyright © 2011-2022 走看看