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;

        }

    }

  • 相关阅读:
    说一说javascript的异步编程
    Flink 整合 Nacos,让 Flink 作业配置动态更新不再是难事
    Flink 整合 Apollo,动态更新 Flink 作业配置
    一文让你彻底了解大数据实时计算引擎 Flink
    《大数据实时计算引擎 Flink 实战与性能优化》新专栏
    滴滴实时计算发展之路及平台架构实践
    Flink 从 0 到 1 学习 —— Flink Data transformation(转换)
    Flink Connector 深度解析
    Flink 从 0 到 1 学习 —— Flink 配置文件详解
    vue-cli3如何配置 eslint 及配合 vscode 自动保存
  • 原文地址:https://www.cnblogs.com/daaiwusehng/p/4975442.html
Copyright © 2011-2022 走看看