PYTableViewController框架

4 篇文章 0 订阅
3 篇文章 0 订阅

最近,花了4天的时间,写了一个PYTableViewController框架。如果你使用后觉得还不错的话,可以点点github上右上角的star.

我的github地址:https://github.com/iphone5solo/PYTableViewController

下面是关于框架的介绍:

PYTableViewController

  • 这是一款对系统的UITableViewController的封装。通过简单的操作,快速完成一个基本的tableViewController

内容

什么地方会用到PYTableViewController

  • 几乎每个像样软件都会用到UITableViewController,所以你就可以使用到PYTableViewController
  • 主要用在我的模块、个人信息设置等。如下是各大流行软件使用UITableViewContller的截图

(img1)
(img1)
(img1)
(img1)
(img1)
(img1)
(img1)

PYTableViewController框架的主要类

本框架的设计是使用MVC设计模式,所有组和cell都是通过模型PYGroupPYCell这两个类及其子类组成

PYCell的子类


PYArrowCell     PYCheckCell   PYDetailCell  
PYLabelCell     PYSwitchCell

PYTableViewController


@interface PYTableViewController : UITableViewController

/** tableView的所有组,包含着是PYGroup模型 */
@property (nonatomic, strong) NSMutableArray *groups;

/** 选中的cell */
@property (nonatomic, strong) PYTableViewCell *selectedCell;

@end

PYGroup



@interface PYGroup : NSObject

/** 头部标题 */
@property (nonatomic, copy) NSString *header;

/** 尾部标题 */
@property (nonatomic, copy) NSString *footer;

/** 每一组所有的cells,每一组都是PYCell模型 */
@property (nonatomic, strong) NSMutableArray *cells;

@end

如何使用PYTableViewController

  • 手动导入:
    • PYTableViewContreoller文件夹中的所有文件拽入项目中
    • 创建一个tableViewController继承PYTableViewController

具体使用(详情见示例程序中的PYExampleTableViewController):

  1. 通过继承PYTableViewController类创建tableViewController
  2. 通过模型PYGroup创建组group
  3. 通过模型PYCell及其子类模型创建cell
  4. 添加所有cell到group.cells数组中
  5. 添加所有组到tableViewController.groups数组中

示例代码:

  // 以下代码是放在继承PYTableViewController的tableViewController的viewDidLoad方法中,self代表tableViewController对象

  // 1. 创建组group
  PYGroup *group = [[PYGroup alloc] init];

  // 2. 创建cell
  PYCell *cell = [PYCell cellWithTitle:PYTitle];

  // 3. 添加所有cell
  group.cells = (NSMutableArray *)@[cell1];

  // 4. 把组添加到所以组中
  [self.groups addObject:group];

为选中cell时添加操作

注意:当下面两种方法同时实现,优先选用回调对象(target)和回调方法(SEL),即block不再调用
  • 通过回调(block)
 // 在创建cell时,直接通过block为选中cell添加操作。
  PYArrowCell *cell = [PYArrowCell cellWithTitle:PYTitle didSelectedCell:^(PYTableViewCell *selectedCell, UITableView *tableView) {
    // 使用者可以直接在这里写相应的操作代码
  }];
  // 或者
  // 创建cell
  PYArrowCell *cell = [PYArrowCell cellWithTitle:PYTitle accessoryTitle:PYAccessoryTitle];
  // 为cell的option属性赋值一个block添加操作
  cell.option = ^(PYTableViewCell *selectedCell, UITableView *tableView) {
    // 使用者可以直接在这里写相应的操作代码
  };
  • 通过回调对象(target)和回调方法(SEL)
    // 在创建cell时,直接通过添加参数taeget和action为cell添加操作
    PYArrowCell *cell = [PYArrowCell cellWithTitle:PYTitle accessoryTitle:PYAccessoryTitle didSelectedCellTarget:self action:@selector(didSelectedCell:)];
    // 或者
    // 创建cell
    PYArrowCell *cell = [PYArrowCell cellWithTitle:PYTitle accessoryView:accessoryView1];
    // 设置回调对象
    cell.target = self;
    // 设置回调方法(使用者可以直接在这个方法中添加相应的操作代码)
    cell.action = @selector(didSelectedCell:);

期待

  • 如果在使用过程中遇到BUG,希望您呢个Issues我,谢谢(或者尝试下载最新的框架代码看看BUG修复没有)
  • 如果在使用过程中发现功能不够用,希望你能Issues我,我非常想为这个框架增加更多好用的功能,谢谢
  • 如果你想为PYTableViewController输出代码,请拼命Pull Requests我
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值