zoukankan      html  css  js  c++  java
  • "首页添加至购物车,TabBar显示购物车的数量"实现

    今天学习别人的项目源码的时候,看到这样的一种实现功能:首页添加至购物车,TabBar显示购物车的数量....想到以前没有做过,这里学习了,记录一下:

    实现的效果图如下:

    当点击首页添加至购物的操作的时候,Tabbar的购物车item显示购物车数量的badge的角标.

    实现思路其实很简单:

    就是在执行添加至购物车的操作时,发一个通知,改变Tabbar的购物车item显示购物车数量的badge的角标的显示数量.

    注意: 当为0时,要置为nil,否则会显示0的,这样是不可以的.

    实现的主要代码如下 :

    // 接受通知
    - (void)addNotification{ [AJNotification addObserver:self selector:@selector(IncreaseShoppingCart) name:LFBShopCarBuyNumberDidChangeNotification object:nil]; }

    // 接收通知的操作
    - (void)IncreaseShoppingCart{ UIViewController *shoppingVC = self.childViewControllers[2]; NSInteger shoppingIndex = [[AJUserShopCarTool sharedInstance]getShopCarGoodsNumber]; if (shoppingIndex == 0) { shoppingVC.tabBarItem.badgeValue = nil; return; } shoppingVC.tabBarItem.badgeValue = [NSString stringWithFormat:@"%zd",shoppingIndex]; }

    // 注销通知
    - (void)dealloc{ [AJNotification removeObserver:self]; }
  • 相关阅读:
    Codeforces 812E Sagheer and Apple Tree
    bzoj 4765: 普通计算姬
    bzoj 4552: [Tjoi2016&Heoi2016]排序
    bzoj 1096: [ZJOI2007]仓库建设
    bzoj 1030: [JSOI2007]文本生成器
    bzoj 1095: [ZJOI2007]Hide 捉迷藏
    JS实现HashMap
    A4纸表格打印
    JAVA字符串格式化-String.format()的使用
    证书打印CSS知识点总结
  • 原文地址:https://www.cnblogs.com/pengsi/p/5990008.html
Copyright © 2011-2022 走看看