首页 技术 正文
技术 2022年11月8日
0 收藏 811 点赞 1,359 浏览 2271 个字

概述

我们在开发的过程中,经常需要重复的写个人中心设置的代码,很多情况下,我们都是通过if(indexPath.row)来判断操作以及要跳转的页面,这样的情况是非常不友好的,尤其是当我们需要调整显示顺序、给点击添加处理等。

通用设置部分界面如下:

iOS YSMine 通用设置   iOS YSMine 通用设置

项目说明

该通用代码,我直接写在了YSKit(点击下载),项目结构如图

iOS YSMine 通用设置

类说明:

iOS YSMine 通用设置

我们在使用的时候,可以通过两种方式,一种是直接继承于YSMineViewController,另一种是使用数据源方式YSMineCellDataSource

承于YSMineViewController

这种方式简单,本身就是一个tableViewController了,直接设置数据源即可,如:

#import "YSMineDemoViewController.h"
#import "YSMine.h"
#import "YSMineSettingViewController.h"@implementation YSMineDemoViewController- (void)viewDidLoad
{
[super viewDidLoad]; [self setupGroups];
}/**
* 初始化模型数据
*/
- (void)setupGroups
{
[self setupGroup0];
[self setupGroup1];
}- (void)setupGroup0
{
// 1.创建组
YSMineCellGroup *group = [YSMineCellGroup group];
group.header = @"这是第一组头部";
group.footer = @"这是第一组底部";
[self.groups addObject:group]; // 2.设置组的所有行数据
YSMineCellItemArrow *newFriend = [YSMineCellItemArrow itemWithTitle:@"帐号管理"];
newFriend.destVcClass = [YSMineSettingViewController class]; YSMineCellItemArrow *securityAccount = [YSMineCellItemArrow itemWithTitle:@"帐号安全"];
securityAccount.destVcClass = [YSMineSettingViewController class]; group.items = @[newFriend,securityAccount];
}- (void)setupGroup1
{
// 1.创建组
YSMineCellGroup *group = [YSMineCellGroup group];
group.header = @"这是第二组";
[self.groups addObject:group]; // 2.设置组的所有行数据
YSMineCellItemArrow *theme = [YSMineCellItemArrow itemWithTitle:@"主题、背景"];
theme.destVcClass = [YSMineSettingViewController class]; YSMineCellItemArrow *notification = [YSMineCellItemArrow itemWithTitle:@"通知"];
notification.destVcClass = [YSMineSettingViewController class]; group.items = @[theme,notification];
}@end

YSMineCellDataSource数据源方式

使用数据源方式,是因为当前ViewController并不是tableViewController,可能还嵌套着其它页面。因此相对来说设置就会多一步,注意红色框的,设置数据源是一样的。

iOS YSMine 通用设置

部分使用代码说明

使用很简单,所有的操作都是设置数据源的时候定义好了

- (void)setupGroup0
{
// 1.创建组
YSMineCellGroup *group = [YSMineCellGroup group];
group.header = @"这是第一组头部";
group.footer = @"这是第一组底部";
[self.groups addObject:group]; // 2.设置组的所有行数据
YSMineCellItemArrow *accountManage = [YSMineCellItemArrow itemWithTitle:@"帐号管理"]; // 右边显示的是箭头
accountManage.destVcClass = [YSMineSettingViewController class]; // 设置点击该Cell要跳转的页面
accountManage.operation = ^(){ // 需要执行的Block
// 需要执行的代码
}; YSMineCellItemSwitch *notifition = [YSMineCellItemSwitch itemWithTitle:@"显示通知"]; // 右边显示的是开头 YSMineCellItemLabel *contactUs = [YSMineCellItemLabel itemWithTitle:@"联系我们"]; // 右边显示的是文本
contactUs.text = @"QQ:123456"; // 设置右边显示的文件 group.items = @[accountManage,notifition,contactUs];
}

上面代码的效果

iOS YSMine 通用设置

源代码下载:点击下载

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,156
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,624
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,468
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,240
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,876
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,043