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;

    }

}

转载于:https://www.cnblogs.com/daaiwusehng/p/4975442.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值