zoukankan      html  css  js  c++  java
  • tableView的懒懒的跳转方式,加载数据源方式

    二者差不多,拿数据源说吧,n个section,每个section里面cell个数不固定,数据源内容不一定,导致cell形式会不一样

    从数据源中取如果写if else,或者switch都不满意,也许Swift更牛一些,这里不提

    说白了就是想根据所具有资源计算出不同cell对应的唯一的数据源数组的索引值

    写的不好,如果有更好的希望分享一下,互相学习!(几十个scetion应该没有明显的效率诧异)

    不多说上代码:

    -(NSArray *)arrayTitle

    {

        if (!_arrayTitle) {

            

            _arrayTitle = @[@"不让他(她)看我的家谱",@"不让他(她)看我的动态",@"不看他(她)的动态"];

        }

        return @[@"不让他(她)看我的家谱",@"不让他(她)看我的动态",@"不看他(她)的动态"];

    }

    -(NSArray *)arrayVCForJump

    {

        if (!_arrayVCForJump) {

            _arrayVCForJump = @[[MHNotShowFamilyTreeController class],[MHNotShowEventToOtherController class],[MHNotSeeOtherEventController class]];

        }

        return _arrayVCForJump = @[[MHNotShowFamilyTreeController class],[MHNotShowEventToOtherController class],[MHNotSeeOtherEventController class]];

    }

    #pragma mark计算出当前数组的索引值,根据indexPath保证不会因为section多而重复

    -(NSInteger)getCurrentIndexForDataArray:(NSIndexPath*)indexPath tableView:(UITableView *)tableView

    {

        //****************

        self.numOfIndexPromate =0;

        

        for (NSInteger i=0; i<indexPath.section; i++) {

            self.numOfIndexPromate += [tableView numberOfRowsInSection:i];

        }

       

        //***************

        return self.numOfIndexPromate;

    }

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

    {

        

        //cell很少暂时可不考虑重用

        MHPrivacyTableViewCell * cell = [[MHPrivacyTableViewCell alloc]init];

        cell.textLabel.textColor = MHEventCellTitleColor;

    //    cell.textLabel.text = self.arrayTitle[indexPath.row+indexPath.section];//此处取值在多个section不唯一,以后要注意

        NSInteger num = [self getCurrentIndexForDataArray:indexPath tableView:tableView];

        cell.textLabel.text = self.arrayTitle[num+indexPath.row];

        return cell;

    }

    #pragma mark - 点击cell跳转代理

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

    {

        NSInteger num = [self getCurrentIndexForDataArray:indexPath tableView:tableView];

        Class strVcName = self.arrayVCForJump[indexPath.row+num];

    //    Class strVcName = self.arrayVCForJump[indexPath.row+indexPath.section];

        NSString * strClassName = NSStringFromClass(strVcName);

        if ([strClassName isContainOneStr:@"Controller"]) {

            UIViewController * vc = [[strVcName alloc]init];

            [self.navigationController pushViewController:vc animated:YES];

        }

        else

        {

            return;

        }

    }

  • 相关阅读:
    kubeadm部署K8S集群v1.16.3
    MySQL5.7Gtid主从复制总是遇到日志被清等出现无法正常主从复制
    ORACLE数据库SQL优化 not in 与not exits
    某控股公司OA系统ORACLE DG搭建
    阿里云ECS服务器上搭建keepalived+mha+mysql5.6+gtid+一主两从+脚本判断架构踩的坑
    生产案例:开发不小心把某个表数据清了,没有逻辑备份,有物理备份
    生产案例:突然产生大量的归档日志,导致磁盘空间满了无法登陆数据库
    maxscale读写分离
    MYSQL EXPLAIN执行计划命令详解(支持更新中)
    vue 解决 post请求下载文件,下载的文件损坏打不开,结果乱码
  • 原文地址:https://www.cnblogs.com/daaiwusehng/p/4975442.html
Copyright © 2011-2022 走看看