上篇博客写了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. loadrunner录制上传文件,但是回放失败

    用Loadrunner录制上传文件,脚本回放时发现,文件没有上传成功,检查脚本发现脚本中没有上传文件的路径. 脚本录制时选择的协议,如果说是socket协议,则不需要上传文件的路径,Loadrunne ...

  2. python中字符串和列表只是汇总

    字符串知识汇总 字符串是描述变量的重要信息,其中的应用也是很多,很重要的一点就是StringBuilder.今天我们会为大家介绍一下常用的StringBuilder 1 strip lstrip rs ...

  3. python初识(一)

    python语言的发展 python语言诞生于1990年,由Guido van Rossum设计并领导开发. 1989年12月,Guido为打发圣诞节时间而开发的项目. python名字的由来,由于当 ...

  4. es6学习笔记--新数据结构Set,Map以及WeakSet,WeakMap

    在javascript中,存储数据的方式大部分就是以数组或者对象形式存储的,es6出现了4种新集合Set,Map,WeakSet,WeakMap来存储数据,简化了编程. 集合--Set 类似于数组,但 ...

  5. UITableViewStyleGrouped模式下烦人的多余间距

    第一个section上边多余间距处理 // 隐藏UITableViewStyleGrouped上边多余的间隔 _tableView.tableHeaderView = [[UIView alloc] ...

  6. Redis一次数据丢失(转)

    一台Redis服务器,4核,16G内存且没有任何硬件上的问题.持续高压运行了大约3个月,保存了大约14G的数据,设置了比较完备的Save参数.而就是这台主机,在一次重起之后,丢失了大量的数据,14G的 ...

  7. Linux运维人员共用root帐户权限审计(转至马哥Linux运维)

    一.应用场景 在中小型企业,公司不同运维人员基本都是以root 账户进行服务器的登陆管理,缺少了账户权限审计制度.不出问题还好, 出了问题,就很难找出源头.这里介绍下,如何利用编译bash 使不同的客 ...

  8. maven库

    1.本地仓库 本地仓库是你本地的一个山寨版,只有你看的到,主要起缓存作用. 当你向仓库请求插件或依赖的时候,会先检查本地仓库里是否有.如果有则直接返回,否则会向远程仓库请求,并做缓存. 本地仓库默认在 ...

  9. oracle--dba和表的备份与恢复

    数据库管理员 每个oracle数据库应该至少有一名数据库管理员(dba),对于一个小的数据库,一个dba就够了,但是对于一个大的数据库可能需要多个dba分别担负不同的管理职责,那么一个数据库管理员的主 ...

  10. 让Myeclipse自动生成的get set方法 自动加上文本注释,并且注释内容包含字段中我们加的文档注释

    在进行编码写实体类的时候发现,一个实体类有好多的字段要进行注释,他们都是私有的不能直接访问,我们在写的时候加入的文档注释也起不到效果,但是自动生成的get,set方法的文档注释有不符合我们要求(没有包 ...