iOS开发之基类BaseViewController和BaseTableViewController应该做哪些事情

前言

对于所有开发者而言,使用最少的代码实现必须的功能的前提下,写得一手漂亮整洁的代码是多么有成就感和美观感。那应该如何实现呢?
1、复用布局相似的view、cell、viewController;
2、封装经常使用的工具类;
3、抽取重复使用的方法;
4、创建一个很好地基类(父类)Base类;
等等.....

BaseViewController应该做哪些事情呢?

.h文件:

//左右导航按钮回调

typedef void(^PassAction)(UIButton *button);


//刷新按钮回调

typedef void(^RefreshAction)();


//传值回调

typedef void(^PassStr)(NSString *);


@interface FDBaseViewController : UIViewController


@property (copy, nonatomic) PassAction leftItemAction;

@property (copy, nonatomic) PassAction rightItemAction;

@property (copy, nonatomic) RefreshAction refreshAction;

@property (copy, nonatomic) PassStr passStr;



- (void)setNavigationBarTitle:(NSString *)title;


/**

 *  设置navigation背景透明

 */

- (void)setNavigationBackGroudDiaphanous;


/**

 *  设置navigation背景不透明

 */

- (void)setNavigationBackGroudOpaque;


#pragma mark ===== leftBarButton


/**

 *  设置navigation左按钮(图片)

 *

 *  @param image     normal图片

 *  @param highImage 高亮图片

 */

- (void)setNavigationBarLeftItemimage:(NSString *)image highImage:(NSString *)highImage;


/**

 *  设置navigation左按钮(文字)

 *

 *  @param title 按钮文字

 */

- (void)setNavigationBarLeftItemButttonTitle:(NSString *)title;


/**

 *  设置navigation左按钮(图片 + 文字)

 *

 *  @param title 文字

 *  @param image 图片

 */

- (void)setNavigationBarLeftItemButtonTitle:(NSString *)title image:(NSString *)image;


#pragma mark ===== rightBarButton

/**

 *  设置navigation右按钮

 *

 *  @param image     正常图片

 *  @param highImage 高亮图片

 */

- (void)setNavigationBarRightItemimage:(NSString *)image highImage:(NSString *)highImage;

/**

 *  设置navigation右按钮(文字)

 *

 *  @param title 按钮文字

 */

- (void)setNavigationBarRightItemButttonTitle:(NSString *)title;


/**

 *  设置navigation右按钮(图片 + 文字)

 *

 *  @param title 文字

 *  @param image 图片

 */

- (void)setNavigationBarRightItemButtonTitle:(NSString *)title image:(NSString *)image;



BaseTableViewController应该做哪些事情呢?

.m文件:

- (void)loadView

{

    [super loadView];

    self.baseTableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:UITableViewStyleGrouped];

    self.view = self.baseTableView;

}


- (void)dealloc

{

    self.baseTableView.emptyDataSetSource = nil;

    self.baseTableView.emptyDataSetDelegate = nil;

    self.baseTableView.delegate = nil;

    self.baseTableView.dataSource = nil;

}


- (void)viewDidLoad {

    [super viewDidLoad];

    

    self.baseTableView.delegate = self;

    self.baseTableView.dataSource = self;

    

    self.baseTableView.emptyDataSetSource = self;

    self.baseTableView.emptyDataSetDelegate = self;

    //自适应

    self.baseTableView.estimatedRowHeight = 1000;

    self.baseTableView.rowHeight = UITableViewAutomaticDimension;

    

    [self.baseTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];

    

    // Uncomment the following line to preserve selection between presentations.

    // self.clearsSelectionOnViewWillAppear = NO;

    

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.

    // self.navigationItem.rightBarButtonItem = self.editButtonItem;

}

//公共方法----配置统一的样式

- (void)confignBaseTableView

{

    self.baseTableView.sectionFooterHeight = 0;

    self.baseTableView.sectionHeaderHeight = 20;

    self.baseTableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, SCREEN_WIDTH, 20.01f)];

}



  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sailip

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值