PYTableViewController
这是一个对系统自带的UITableViewController的封装的tableViewController框架,通过简单的操作,快速完成一个基本的tableViewController
Install / Use
/learn @ko1o/PYTableViewControllerREADME
PYTableViewController
- 这是一款对系统的UITableViewController的封装。通过简单的操作,快速完成一个基本的tableViewController
内容
-
开始
-
框架使用
<a id="什么地方会用到PYTableViewController"></a>什么地方会用到PYTableViewController
- 几乎每个像样软件都会用到UITableViewController,所以你就可以使用到PYTableViewController
- 主要用在
我的模块、个人信息、设置等。如下是各大流行软件使用UITableViewContller的截图
<a id="PYTableViewController框架的主要类"></a>PYTableViewController框架的主要类
本框架的设计是使用MVC设计模式,所有组和cell都是通过模型PYGroup、PYCell这两个类及其子类组成
<a id="PYCell的子类"></a>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
<a id="如何使用PYTableViewController"></a>如何使用PYTableViewController
- 手动导入:
- 将
PYTableViewContreoller文件夹中的所有文件拽入项目中 - 创建一个tableViewController继承
PYTableViewController
- 将
<a id="具体使用(详情见示例程序中的PYExampleTableViewController)"></a>具体使用(详情见示例程序中的PYExampleTableViewController):
- 通过继承
PYTableViewController类创建tableViewController - 通过模型
PYGroup创建组group - 通过模型
PYCell及其子类模型创建cell - 添加所有cell到group.cells数组中
- 添加所有组到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];
<a id="为选中cell时添加操作"></a>为选中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:);
<a id="期待"></a>期待
- 如果在使用过程中遇到BUG,希望您呢个Issues我,谢谢(或者尝试下载最新的框架代码看看BUG修复没有)
- 如果在使用过程中发现功能不够用,希望你能Issues我,我非常想为这个框架增加更多好用的功能,谢谢
- 如果你想为PYTableViewController输出代码,请拼命Pull Requests我
Related Skills
node-connect
339.5kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
339.5kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.9kCommit, push, and open a PR
