【iOS】 含tableView的ViewController基类的实现
上篇博客写了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基类的实现的更多相关文章
- iOS 基于MVC设计模式的基类设计
iOS 基于MVC设计模式的基类设计 https://www.jianshu.com/p/3b580ffdae00
- ios中解析json对象基类
这个是对上面一篇写的一个解析json对象的基类 @interface BaseObjectFromJson : NSObject + (id) objectWithDict:(NSDictionary ...
- Viewcontroller基类
#import <UIKit/UIKit.h> #import "YQZMutableArray.h" @interface YQZViewController : U ...
- iOS控制器之基类设计
题记 在进入新公司后.经过这一个月的重构项目,终于把项目做到了个人相对满意的程度(还有一种不满意的叫老板的需求,提过多次意见也没用= =!).在这次重构中按照以前的思路设计出了个人觉得比较适用的一个基 ...
- 虚析构函数? vptr? 指针偏移?多态数组? delete 基类指针 内存泄漏?崩溃?
五条基本规则: 1.如果基类已经插入了vptr, 则派生类将继承和重用该vptr.vptr(一般在对象内存模型的顶部)必须随着对象类型的变化而不断地改变它的指向,以保证其值和当前对象的实际类型是一致的 ...
- 无线客户端框架设计(3):基类的设计(iOS篇)
本文代码:YoungHeart-Chapter-03.zip 没有基类的App都不是好App. 因为iOS使用的是mvc模式的开发模式,所以,业务逻辑基本都在每个页面相应的ViewController ...
- 【iOS】UIViewController基类的实现
继承是面向对象编程语言的三大特性之一,写好基类会给App的开发带来极大的方便.在iOS开发中,一般一个页面就对应一个ViewController,ViewController在开发中用的也很多,写一个 ...
- iOS Foundation 框架基类
iOS Foundation 框架基类 太阳火神的漂亮人生 (http://blog.csdn.net/opengl_es) 本文遵循"署名-非商业用途-保持一致"创作公用协议 转 ...
- C++ Pirmer : 第十五章 : 面向对象程序设计之基类和派生的定义、类型转换与继承与虚函数
基类和派生类的定义以及虚函数 基类Quote的定义: classs Quote { public: Quote() = default; Quote(cosnt std::string& bo ...
随机推荐
- Hadoop的Archive归档命令使用指南
hadoop不适合小文件的存储,小文件本省就占用了很多的metadata,就会造成namenode越来越大.Hadoop Archives的出现视为了缓解大量小文件消耗namenode内存的问题. 采 ...
- Wp-UserAgent——让WordPress在评论后面加上浏览器和操作系统信息
在很多的博客网站都看到过在评论的后面显示了浏览器和操作系统的信息,网上也用过一些插件,但是都不是很好看,有一次在一个网页上看见了这个评论后面不仅显示了浏览器和操作系统的图片,还有文字信息, 感觉不错, ...
- Centos搭建开发环境,PHP7+ Nginx1.12+ Mysql5.7
1.更新yum源 yum -y update 2. 安装 epel-release yum install epel-release -y 检测安装成功:yum search nginx 结果含有: ...
- Linux乱码问题解决
语言设置常用命令 # echo $LANG # locale # LANG=zh_CN.UTF-8 # LANG=en Centos6中文语言包的设置 安装CentOS时选择了中文,但在终端不能显 ...
- GEETEST极验召集互联网大佬齐聚光谷,共同探讨交互安全问题
全球互联网技术在飞速发展的同时,网络安全事件也随之频发.除了直接带来经济损失的网络恶意攻击之外,企业在多个方面也遭受着不同程度的网络恶意攻击,包括品牌形象.管理时间.企业竞争力.客户成交量.用户行为等 ...
- 笔记:Hibernate 拦截器和事件
Hibernate 在执行持久化的过程中,应用程序通常无法参与其中,通过事件框架,Hibernate 允许应用程序能响应特定的内部事件,从而允许实现某些通用的功能,或者对 Hibernate 进行扩展 ...
- 前端Blob对二进制流数据的处理方式
var xhr = new XMLHttpRequest(); xhr.open("post", "/login/getCaptcher?t=" + Math. ...
- 排序算法Java实现(归并排序)
算法描述:对于给定的一组记录,首先将每两个相邻的长度为1的子序列进行归并,得到 n/2(向上取整)个长度为2或1的有序子序列,再将其两两归并,反复执行此过程,直到得到一个有序序列. package s ...
- Redis相关命令
一.命令示例 1. KEYS/RENAME/DEL/EXISTS/MOVE/RENAMENX: #在Shell命令行下启动Redis客户端工具. /> redis-cli #清空当前选择的数据库 ...
- 使用gevent提高IO繁忙型wsgi服务的并发量(转)
add by zhj: 在Benchmark of Python WSGI Servers一文中,作者进行详细分析,得出的结论是gevent在所有WSGI Server(包括Tornado.Uwsgi ...