IOS——TableView 中利用Item模型进行 Cell 的开发(1)TableView 篇

在开发当中,我们遇到过最多的就是 TableView 的界面,小编可以说,基本上每个界面都是用 tableView 做开发的。那么,这么多个 TableView 做开发,遇到的一个问题就是,一直编写对 cell 的控制好麻烦,OC 是一门面向对象的语言,我们要用的是面向对象的思想去开发,MVC 模式,控制器更多的是为试图配置数据,那么如果才能达到快速的用一行代码创建一个 cell 呢,这就是作者今天要说的主题了。

本文章可能各位需要些时间进行消化,本人就是依靠这些技巧达到2周内开发一个 App 并成功上架,这是一套框架,本人目前还在完善,如果有大神觉得那里需要改进,请指点,谢谢,作者很需要成长。

首先,我们要创建一个父类的 TableViewController,这个父类会帮我们处理各种 Item 模型(就是 cell 的数据模型,下文统一叫 Item 模型)的操作。

// 这三个属性放外面主要是方便子类调用的公有属性
@interface FSBaseTableViewController ()
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,assign) UITableViewStyle tableViewStyle;
@property (nonatomic,strong) NSMutableArray *dataSource;
@end
@implementation FSBaseTableViewController

#pragma mark - system method
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view addSubview:self.tableView];
    }



#pragma mark - UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.dataSource.count;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
#import "LHDBaseTableViewCell.h" @interface LHDBaseTableView : UITableView <UITableViewDataSource,UITableViewDelegate> @property (nonatomic, assign) CGFloat cellHeight; @property (nonatomic, assign) BOOL fixed; //是否固定高度 @property (nonatomic, copy) NSInteger(^tableViewNumberOfRowInSection)(UITableView *,NSInteger); @property (nonatomic, copy) UITableViewCell *(^tableViewCellForRowAtIndexPath)(UITableView *, NSIndexPath *); @property (nonatomic, copy) NSInteger(^numberOfSectionInTabelView)(UITableView *); @property (nonatomic, copy) CGFloat(^tableViewHeightForRowAtIndexPath)(UITableView *,NSIndexPath *); @property (nonatomic, copy) BOOL(^tableViewCanEditRowAtIndexPath)(UITableView *,NSIndexPath *); @property (nonatomic, copy) void(^tableViewCommitEditingStyleforRowAtIndexPath)(UITableView *,UITableViewCellEditingStyle,NSIndexPath *); @property (nonatomic, copy) UITableViewCellEditingStyle (^tableViewEditingStyleForRowAtIndexPath)(UITableView *,NSIndexPath *); @property (nonatomic, copy) void(^tableViewDidSelectRowAtIndexPath)(UITableView *,NSIndexPath *); @property (nonatomic, copy) void(^tableViewDidDeselectRowAtIndexPath)(UITableView *,NSIndexPath *); @property (nonatomic, copy) UIView *(^tableViewViewForHeaderInSection)(UITableView *,NSInteger); @property (nonatomic, copy) CGFloat(^tableViewHeightForHeaderInSection)(NSInteger); @property (nonatomic, strong) LHDBaseTableViewCell *myTableViewCell; @property (nonatomic, strong) NSArray *dataArray; - (void)resetDelegate;

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值