• 将一种cell当做几种cell使用


    将一种cell当做几种cell使用

    将一种cell当做几种cell用是有着一些意义的,比如,有时候,不同的cell之间差异很小,如果再派生一个cell出来,就会显得很麻烦,这时候,将这个cell当做几个cell用才有市场的说:)

    效果:

    源码:

    ModelCell.h 与 ModelCell.m

    //
    //  ModelCell.h
    //  Cells
    //
    //  Copyright (c) 2014年 Y.X. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    @interface ModelCell : UITableViewCell
    
    @property (nonatomic, assign) BOOL  show1;
    @property (nonatomic, assign) BOOL  show2;
    @property (nonatomic, assign) BOOL  show3;
    
    @end

    RootViewController.m

    //
    //  RootViewController.m
    //  Cells
    //
    //  Copyright (c) 2014年 Y.X. All rights reserved.
    //
    
    #import "RootViewController.h"
    #import "ModelCell.h"
    
    @interface RootViewController ()<UITableViewDataSource, UITableViewDelegate>
    
    @property (nonatomic, strong) UITableView  *tableView;
    @property (nonatomic, strong) NSArray      *dataSource;
    
    @end
    
    @implementation RootViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        // tableView
        _tableView = [[UITableView alloc] initWithFrame:self.view.bounds
                                                  style:UITableViewStylePlain];
        _tableView.dataSource     = self;
        _tableView.delegate       = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self.view addSubview:_tableView];
    }
    
    #pragma mark - UITableView's dataSource & delegate
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        return 100;
    }
    
    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        static NSString *reusedFlag = @"YouXianMing";
        ModelCell *cell = [tableView dequeueReusableCellWithIdentifier:reusedFlag];
        if (cell == nil) {
            cell = [[ModelCell alloc] initWithStyle:UITableViewCellStyleDefault
                                    reuseIdentifier:reusedFlag];
        }
        
        cell.show1 = YES;
        cell.show2 = YES;
        cell.show3 = YES;
        
        return cell;
    }
    
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return 100.f;
    }
    
    @end

    核心的地方:

    根据属性的setter方法动态隐藏cell中的某些控件

    然后在配置cell的时候动态设定要显示的控件

    just so easy :)

  • 相关阅读:
    如何通过wlst部署应用程序到weblogic12c上
    Oracle数据库账户口令复杂度-等保测评之身份鉴别
    等保测评中与oracle有关的工作
    如何做好项目管理工作
    weblogic 安全漏洞 CVE-2017-5638
    中间件中文技术文档2018年3月-5月更新内容
    Admin Console 反应慢的相关bug
    HotSpot jdk 资料汇总
    weblogic patch log显示
    Where Can I Download Full Installers for WebLogic Server
  • 原文地址:https://www.cnblogs.com/YouXianMing/p/3911706.html
Copyright © 2020-2023  润新知