首页
/ JMStaticContentTableViewController 技术文档

JMStaticContentTableViewController 技术文档

2024-12-25 03:10:04作者:郁楠烈Hubert

1. 安装指南

使用 CocoaPods 安装

若您的项目已使用 CocoaPods,请将以下代码添加到您的 Podfile 文件中:

dependency 'JMStaticContentTableViewController'

然后执行 pod install 命令以安装依赖。

手动安装

您可以下载源文件或将其作为 git submodule 添加到项目中。以下是如何作为 submodule 添加的步骤:

$ cd YourProject
$ git submodule add https://github.com/jakemarsh/JMStaticContentTableViewController.git Vendor/JMStaticContentTableViewController

将文件夹 "JMStaticContentTableViewController" 中的所有文件添加到您的项目中。

ARC

JMStaticContentTableViewController 使用 Automatic Reference Counting (ARC)。如果您的项目未使用 ARC,您需要在所有 JMStaticContentTableViewController 源文件上设置 -fobjc-arc 编译器标志。在 Xcode 中,选择活动目标并选择 "Build Phases" 选项卡。在 "Compiler Flags" 列中,为每个 JMStaticContentTableViewController 源文件设置 -fobjc-arc

2. 项目使用说明

JMStaticContentTableViewController 是一个 UITableViewController 的子类,用于简单快速地显示“静态内容”。这种内容的一个例子是 iOS 内置设置应用程序中的内容。它还可以轻松创建用于收集信息的 UITableViewControllers

此库使用了非常酷的块(block)方法,并且允许您轻松创建具有不同样式的表格视图单元格,以及为单元格的选中事件添加回调。

3. 项目API使用文档

以下是 JMStaticContentTableViewController 的一些基本用法示例:

添加一个节和单元格

在您的 viewDidLoad 方法中,您可以按照以下方式添加节和单元格:

- (void)viewDidLoad {
    [super viewDidLoad];

    [self addSection:^(JMStaticContentTableViewSection *section, NSUInteger sectionIndex) {
        [section addCell:^(JMStaticContentTableViewCell *staticContentCell, UITableViewCell *cell, NSIndexPath *indexPath) {
            staticContentCell.cellStyle = UITableViewCellStyleValue1;
            staticContentCell.reuseIdentifier = @"DetailTextCell";

            cell.textLabel.text = NSLocalizedString(@"Wi-Fi", @"Wi-Fi");
            cell.detailTextLabel.text = NSLocalizedString(@"T.A.R.D.I.S.", @"T.A.R.D.I.S.");
        } whenSelected:^(NSIndexPath *indexPath) {
            [self.navigationController pushViewController:[[WifiViewController alloc] init] animated:YES];
        }];
    }];
}

在运行时插入单元格

此方法与 addCell: 类似,但会使用动画将单元格插入到表格中:

- (void)_someTaskFinished {
    [self insertCell:^(JMStaticContentTableViewCell *staticContentCell, UITableViewCell *cell, NSIndexPath *indexPath) {
        staticContentCell.reuseIdentifier = @"WifiNetworkCell";
        staticContentCell.tableViewCellSubclass = [WifiNetworkTableViewCell class];

        cell.textLabel.text = network.networkName;
        cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;

        cell.indentationLevel = 2;
        cell.indentationWidth = 10.0;
    } whenSelected:^(NSIndexPath *indexPath) {
        // TODO
    } atIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES];
}

在运行时插入多个单元格

与上述方法类似,但这里我们在 beginUpdatesendUpdates 调用中包装我们的工作,以保留 UITableView 的所有内置“魔法”,同时仍然使用我们的简洁语法:

[self.tableView beginUpdates];

for(SomeModelObject *o in self.awesomeModelObjects) {
    [self insertCell:^(JMStaticContentTableViewCell *staticContentCell, UITableViewCell *cell, NSIndexPath *indexPath) {
        staticContentCell.reuseIdentifier = @"SomeCell";

        cell.textLabel.text
    } atIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES];
}

[self.tableView endUpdates];

动画

当您要求 JMStaticContentTableViewController 动画插入或删除单元格或节时,它会在底层使用 UITableViewRowAnimationAutomatic 样式的动画,因此所有动画都会看起来很棒。此样式在 iOS 5 中添加。

4. 项目安装方式

请参考上述 "安装指南" 部分中的内容进行项目安装。您可以使用 CocoaPods 或手动方式添加到项目中。

登录后查看全文
热门项目推荐

热门内容推荐

最新内容推荐

项目优选

收起
openGauss-serveropenGauss-server
openGauss kernel ~ openGauss is an open source relational database management system
C++
136
186
RuoYi-Vue3RuoYi-Vue3
🎉 (RuoYi)官方仓库 基于SpringBoot,Spring Security,JWT,Vue3 & Vite、Element Plus 的前后端分离权限管理系统
Vue
882
523
openHiTLSopenHiTLS
旨在打造算法先进、性能卓越、高效敏捷、安全可靠的密码套件,通过轻量级、可剪裁的软件技术架构满足各行业不同场景的多样化要求,让密码技术应用更简单,同时探索后量子等先进算法创新实践,构建密码前沿技术底座!
C
362
381
ohos_react_nativeohos_react_native
React Native鸿蒙化仓库
C++
182
264
kernelkernel
deepin linux kernel
C
22
5
nop-entropynop-entropy
Nop Platform 2.0是基于可逆计算理论实现的采用面向语言编程范式的新一代低代码开发平台,包含基于全新原理从零开始研发的GraphQL引擎、ORM引擎、工作流引擎、报表引擎、规则引擎、批处理引引擎等完整设计。nop-entropy是它的后端部分,采用java语言实现,可选择集成Spring框架或者Quarkus框架。中小企业可以免费商用
Java
7
0
CangjieCommunityCangjieCommunity
为仓颉编程语言开发者打造活跃、开放、高质量的社区环境
Markdown
1.09 K
0
note-gennote-gen
一款跨平台的 Markdown AI 笔记软件,致力于使用 AI 建立记录和写作的桥梁。
TSX
83
4
cherry-studiocherry-studio
🍒 Cherry Studio 是一款支持多个 LLM 提供商的桌面客户端
TypeScript
613
60
open-eBackupopen-eBackup
open-eBackup是一款开源备份软件,采用集群高扩展架构,通过应用备份通用框架、并行备份等技术,为主流数据库、虚拟化、文件系统、大数据等应用提供E2E的数据备份、恢复等能力,帮助用户实现关键数据高效保护。
HTML
118
78