"Home Add to Cart, Tabbar show the number of shopping carts" implementation

Source: Internet
Author: User

Today to learn other people's project source code, see such a realization function: Homepage added to shopping cart, Tabbar show the number of shopping cart .... Think of not done before, here study, record:

The implementation is as follows:

When you click on the homepage to add to the shopping operation, Tabbar's shopping cart item shows the badge of the shopping cart number.

The realization of the idea is actually very simple:

is to perform the add to cart operation, send a notification, change Tabbar shopping cart Item shows the number of badge of the shopping cart number of corners.

Note: When it is 0 o'clock, it should be set to nil, otherwise it will show 0, which is not possible.

The main code to implement is as follows:

Accept Notifications
- (void) addnotification{[ajnotification addobserver:self selector: @selector (increaseshoppingcart) Name: LfbshopcarbuynumberdidchangenotificationObject: nil];}

Actions to receive notifications- (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];}

Logout Notification- (void) dealloc{[ajnotification removeobserver:self];}

"Home Add to Cart, Tabbar show the number of shopping carts" implementation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.