美文网首页demo
iOS电商项目之分类

iOS电商项目之分类

作者: 葱花饼 | 来源:发表于2017-06-12 09:11 被阅读269次
�分类.PNG

先创建左边的tableView和右边的collectionView

UITableView *tableView = [[UITableView alloc]init];
    self.tableView = tableView;
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.backgroundColor = ControllerBgColor;
    tableView.frame = CGRectMake(0, 64, ScreenWidth / 4, ScreenHeight);
    tableView.showsVerticalScrollIndicator = NO;
    tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    tableView.tableFooterView = [[UIView alloc]init];
    [self.view addSubview:tableView];
    [tableView registerNib:[UINib nibWithNibName:NSStringFromClass([CategoryCell class]) bundle:nil] forCellReuseIdentifier:@"CategoryCell"];
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    layout.minimumLineSpacing = 0.5;
    layout.minimumInteritemSpacing = 0.5;
    CGFloat w = (ScreenWidth - ScreenWidth / 4) / 3 - 0.5;
    CGFloat h = 44;
    layout.itemSize = CGSizeMake(w, h);
    UICollectionView *collectionView = [[UICollectionView alloc]initWithFrame:CGRectZero collectionViewLayout:layout];
    collectionView.delegate = self;
    collectionView.dataSource = self;
    self.collectionView = collectionView;
    collectionView.frame = CGRectMake(tableView.frame.size.width, 64, (ScreenWidth - ScreenWidth / 4), ScreenHeight);
    collectionView.backgroundColor = ControllerBgColor;
    [collectionView registerClass:[UserCell class] forCellWithReuseIdentifier:@"UserCell"];
    [self.view addSubview:collectionView];

点击tableViewCell更新collectionView

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    CategoryModel_result *result = self.categoryModel.result[indexPath.row];
    self.collectionCellArray = result.children;
    [self.collectionView reloadData];
}

collectionView代理实现

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    if (self.collectionCellArray == 0) {
        CategoryModel_result *result = self.categoryModel.result[section];
        return result.children.count;
    } else {
        return self.collectionCellArray.count;
    }
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UserCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"UserCell" forIndexPath:indexPath];
    if (self.collectionCellArray == 0) {
        CategoryModel_result *result = self.categoryModel.result[indexPath.section];
        CategoryModel_result_children *children = result.children[indexPath.row];
        cell.label.text = children.name;
    } else {
        CategoryModel_result_children *children = self.collectionCellArray[indexPath.row];
        cell.label.text = children.name;
    }
    return cell;
}

想要系统,具体的学习,请加群-------群号:647657839

相关文章

  • iOS电商项目之分类

    先创建左边的tableView和右边的collectionView 点击tableViewCell更新collec...

  • iOS电商项目之消息

    订单提醒主要是订单状态发生变化时(发货,退款等)其余显示的就是聊天信息,集成网易云信,聊天列表可以删除。 想要系统...

  • iOS电商项目之设置

    设置包括个人信息设置、修改手机绑定、清除缓存、鼓励反馈、关于我们以及退出登录 想要系统,具体的学习,请加群----...

  • iOS电商项目之退款

    退款包括退款且退货、退款(无需退货) 想要系统,具体的学习,请加群-------群号:647657839

  • iOS电商项目之tabBar

    本项目tabBar点击后是可以变化大小的,具体看效果 设置UITabBarController的代理 实现代理方法...

  • iOS-电商常用分类实现

    电商分类页实现 前言:商品分类页几乎涵盖了所有电商App,实现的方法有很多,今天分享一个在我当前项目应用的实现方法...

  • iOS电商项目之商品详情

    这个模块也挺复杂 导航栏有购物车按钮,更多按钮里包含消息、分享、拷贝,商品首图可以点击放大,放大功能包括双击2倍放...

  • iOS电商项目之确认订单

    确认订单模块包括买家地址、订单信息、发票类型、积分折现,订单信息又分为(单店铺单订单、单店铺多订单,多店铺多订单)...

  • iOS电商项目之商家店铺

    商家店铺分为首页、全部、最新、分类4大模块 首页 全部 全部又分为综合、销量、最新、价格(从低到高、从高到低) 最...

  • iOS电商项目之我的

    我的界面分为头部、我的订单、我的收藏、我的足迹、优惠券、客服服务 我的足迹 按照日期排序进行展示,可以多选,单选删...

网友评论

    本文标题:iOS电商项目之分类

    本文链接:https://www.haomeiwen.com/subject/amakqxtx.html