上篇博客写了ViewController的基类的实现,这篇博客主要写在BaseViewController的基础上实现一个含tableView控件的基类的实现,主要给包含tableView的页面来继承。

BaseTableViewViewController.h代码:

#import "BZBaseViewController.h"
#import "BZBaseTableViewCell.h" @interface BZBaseTableViewViewController : BZBaseViewController<UITableViewDelegate,UITableViewDataSource> @property(nonatomic,strong) UITableView * tableView;
@property(nonatomic,strong) NSArray * dataSource; -(void)setupTableView; @end

BaseTableViewViewController.m代码:

#import "BZBaseTableViewViewController.h"

@interface BZBaseTableViewViewController ()

@end

@implementation BZBaseTableViewViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view. } -(void)setupTableView{
[self.view addSubview:self.tableView];
} #pragma mark - UITableViewDelegate & UITableViewDataSource
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
} -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 0;
} -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 0.0;
} -(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.001;
} -(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 0.001;
} -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
BZBaseTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ID"];
if (!cell) {
cell = [[BZBaseTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ID"];
}
return cell;
} #pragma mark - lazy
-(UITableView *)tableView{
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - self.mNavigationbarHeight) style:UITableViewStyleGrouped];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.showsVerticalScrollIndicator = NO;
_tableView.backgroundColor = [UIColor clearColor];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.estimatedRowHeight = 0;
_tableView.estimatedSectionHeaderHeight = 0;
_tableView.estimatedSectionFooterHeight = 0;
}
return _tableView;
} @end

项目中包含tableView的ViewController都可以继承自该类,重写tableView的代理方法就可以实现相应的功能。

另外,tableView的实现离不开tableViewCell,所以我们也可以写一个BaseTableViewCell,让其他的tableViewCell来继承。

BaseTableViewCell.h代码:

#import <UIKit/UIKit.h>

@interface BZBaseTableViewCell : UITableViewCell

-(void)setupUI;

@end

BaseTableViewCell.m代码:

#import "BZBaseTableViewCell.h"

@implementation BZBaseTableViewCell

- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
} -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
self.selectionStyle = UITableViewCellSelectionStyleNone;
if (self) {
[self setupUI];
}
return self;
} -(void)setupUI{ } - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated]; // Configure the view for the selected state
} @end

继承自BaseTableViewCell的子类直接实现-(void)setupUI;方法即可实现自定义的cell界面。

【iOS】 含tableView的ViewController基类的实现的更多相关文章

  1. iOS 基于MVC设计模式的基类设计

    iOS 基于MVC设计模式的基类设计 https://www.jianshu.com/p/3b580ffdae00

  2. ios中解析json对象基类

    这个是对上面一篇写的一个解析json对象的基类 @interface BaseObjectFromJson : NSObject + (id) objectWithDict:(NSDictionary ...

  3. Viewcontroller基类

    #import <UIKit/UIKit.h> #import "YQZMutableArray.h" @interface YQZViewController : U ...

  4. iOS控制器之基类设计

    题记 在进入新公司后.经过这一个月的重构项目,终于把项目做到了个人相对满意的程度(还有一种不满意的叫老板的需求,提过多次意见也没用= =!).在这次重构中按照以前的思路设计出了个人觉得比较适用的一个基 ...

  5. 虚析构函数? vptr? 指针偏移?多态数组? delete 基类指针 内存泄漏?崩溃?

    五条基本规则: 1.如果基类已经插入了vptr, 则派生类将继承和重用该vptr.vptr(一般在对象内存模型的顶部)必须随着对象类型的变化而不断地改变它的指向,以保证其值和当前对象的实际类型是一致的 ...

  6. 无线客户端框架设计(3):基类的设计(iOS篇)

    本文代码:YoungHeart-Chapter-03.zip 没有基类的App都不是好App. 因为iOS使用的是mvc模式的开发模式,所以,业务逻辑基本都在每个页面相应的ViewController ...

  7. 【iOS】UIViewController基类的实现

    继承是面向对象编程语言的三大特性之一,写好基类会给App的开发带来极大的方便.在iOS开发中,一般一个页面就对应一个ViewController,ViewController在开发中用的也很多,写一个 ...

  8. iOS Foundation 框架基类

    iOS Foundation 框架基类 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转 ...

  9. C++ Pirmer : 第十五章 : 面向对象程序设计之基类和派生的定义、类型转换与继承与虚函数

    基类和派生类的定义以及虚函数 基类Quote的定义: classs Quote { public: Quote() = default; Quote(cosnt std::string& bo ...

随机推荐

  1. 发个2012年用java写的一个控制台小游戏

    时间是把杀狗刀 突然发现了12年用java写的控制台玩的一个文字游戏,有兴趣的可以下载试试哈汪~ 里面难点当时确实遇到过,在计算倒计时的时候用了多线程,当时还写了好久才搞定.很怀念那个时间虽然不会做游 ...

  2. java语言与jvm虚拟机简介

    一.java语言 1.1 支持面向对象编程oop 强调支持,因为java同样可以面向过程编程. oop的三大特性是:封装.继承.多态. 封装主要针对成员变量而言,oop的思想要求成员变量均为私有,不应 ...

  3. LNMP详解

    目录 Nginx配置    1 PHP解析    1 Mysql操作    3 服务安装    3 连接测试    3 数据配置    3 Blogs建立    4   LNMP 环境 Mysql:1 ...

  4. Keeweb-Linux的密码管理器

    Keeweb-Linux的密码管理器 如今,我们依赖于越来越多的线上服务.我们每注册一个线上服务,就要设置一个密码:如此,我们就不得不记住数以百计的密码.这样对于每个人来说,都很容易忘记密码.那么,下 ...

  5. [SCOI2011] 糖果

    luogu Description 幼儿园里有N个小朋友,lxhgww老师现在想要给这些小朋友们分配糖果,要求每个小朋友都要分到糖果.但是小朋友们也有嫉妒心,总是会提出一些要求,比如小明不希望小红分到 ...

  6. python基础学习一 字符串的相关操作

    python的字符串 在python中,字符串是以unicode编码的,所以python的字符串支持多语言 对于单个字符的编码,python提供了ord()函数获取字符的整数表示,chr()函数是把编 ...

  7. Algorithm --> 矩阵链乘法

    动态规划--矩阵链乘法 1.矩阵乘法       Note:只有当矩阵A的列数与矩阵B的行数相等时A×B才有意义.一个m×r的矩阵A左乘一个r×n的矩阵B,会得到一个m×n的矩阵C. #include ...

  8. JQuery代码实现上拉加载(不使用插件)

    <script type="text/javascript"> $(window).scroll(function() { //已经滚动到上面的页面高度 var sl_ ...

  9. centos7上安装ffmpeg

    FFmpeg介绍 FFmpeg是一个开源免费跨平台的视频和音频流方案,属于自由软件,采用LGPL或GPL许可证(依据你选择的组件).它提供了录制.转换以及流化音视频的完整解决方案.它包含了非常先进的音 ...

  10. 算法题丨Longest Consecutive Sequence

    描述 Given an unsorted array of integers, find the length of the longest consecutive elements sequence ...