• iOS YSMine 通用设置


    概述

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

    通用设置部分界面如下:

       

    项目说明

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

     

    类说明:

    我们在使用的时候,可以通过两种方式,一种是直接继承于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,可能还嵌套着其它页面。因此相对来说设置就会多一步,注意红色框的,设置数据源是一样的。

    部分使用代码说明

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

    - (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];
    }

    上面代码的效果

    源代码下载:点击下载

  • 相关阅读:
    MySQL Server 5.0安装教程
    c++实现一个小算法
    spring core 与 context理解
    关于eclipse的mysql连接配置
    eclipse中创建一个maven项目
    Oracle中的多表查询(笛卡尔积原理)
    Vue进阶
    计算机网络基础
    java框架之springboot
    bootstrap学习
  • 原文地址:https://www.cnblogs.com/jys509/p/5608125.html
Copyright © 2020-2023  润新知