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]; }
  • 相关阅读:
    day7 反射
    day7 面向对象进阶
    day7 面向对象class()学习
    day6 subprocess模块、logging模块
    day6 hashlib模块
    day6 ConfigParser模块 yaml模块
    day6 xml文件格式的处理
    day6 shelve模块
    day6 SYS模块
    Servlet的学习之Response响应对象(1)
  • 原文地址:https://www.cnblogs.com/pengsi/p/5990008.html
Copyright © 2011-2022 走看看