IOS_21 Group Purchase _ Controller inheritance diagram

Source: Internet
Author: User
Tags uikit

Eventually:





Controller inheritance diagram:

Description

Click the button on the dock to the left of the main controller,

such as "group Purchase", "collection", "Map",

There are many similarities to the functionality implemented.


Specify the following:

Click "Group buy" to show a group of nine Gongge,

And, when you click on a cell, display the cell's corresponding group purchase details


Click "Collection" to display a nine Gongge in the form of an archived buy model,

And, when you click on a cell, display the cell's corresponding group purchase details


Click "Map" to display the group purchase model in the form of a pin on the Mapview (city name + longitude + latitude + radius for parameter sending request)

Also, click on a pin to display the cell's corresponding group purchase details






The main functions and methods of the above controllers are stated as follows:




The extracted parent class is as follows:

Parent class Showdealdetailcontroller

Responsible for creating and presenting and hiding the packaged "buy details Controller"

Private Member: Cover

  showdealdetailcontroller.h//  Handsome _ buy////  Created by Beyond on 14-8-20.//  Copyright (c) 2014 Com.beyond. All rights reserved.//  base class, parent class, display Order Details controller controller, when you click on XXX, need to show the purchase details, inherit this controller, the internal implementation of the creation and display order Order Details controller, and hidden Order Details Controller #import <UIKit/UIKit.h> @class Deal; @interface showdealdetailcontroller:uiviewcontroller// The data model on which the controller that displays the order details (data source)-(void) ShowDetail: (Deal *) Deal; @end

showdealdetailcontroller.m//Handsome _ buy////Created by Beyond on 14-8-20.//Copyright (c) 2014 Com.beyond. All rights reserved.//base class, parent class, display Order Details controller controller, when you click on XXX, need to show the purchase details, inherit this controller, the internal implementation of the creation and display Order Details controller, as well as hidden Order Details Controller #import " ShowDealDetailController.h "#import" Cover.h "//Real detail Controller with Xib package, when created, to pass in deal data source #import" DealDetailController.h "// Self-encapsulated global Unified style navigation controller #import "BeyondNavigationController.h"//Real detail Controller with XIB package its height is variable, but the width is usually fixed by # define Kdealdetailvcwidth 600@interface Showdealdetailcontroller () {//cover Cover *_cover;} @end @implementation Showdealdetailcontroller#pragma Mark Show details Controller-(void) ShowDetail: (Deal *) deal{//1. Show Cloaking if (_cove    r = = Nil) {_cover = [cover coverwithtarget:self action: @selector (Hidedetail)]; }//Self is just a child (root) controller, the top of self is the navigation bar of the navigation controller, so Self.navigationcontroller is the view that gets the entire navigation controller (including the navigation bar and its root (child) Controller)//???? The width and height of the navigation controller's view (including the navigation bar)????    Because the self controller, each appearance, is first through the navigation controller has been packaged, because the top of self and the navigation bar _cover.frame = self.navigationController.view.bounds; Transparent when created, then black for animationCover.alpha = 0;    [UIView animatewithduration:kdefaultanimduration animations:^{[_cover Alphareset];    }]; // ????        Add to the top of view of the navigation controller (cover the navigation bar and its root controller) [Self.navigationController.view Addsubview:_cover];    2. Create and display the Buy details controller Dealdetailcontroller *DETAILVC = [[Dealdetailcontroller alloc] init]; Important ~ ~ ~ its navigation bar to the left is closed, click on the method to call this controller to perform animation close, created Dealdetailcontroller, the reason is not to dealdetailcontroller inside to set this button, is because inside cannot easily call outside of this hidden Dealdetailcontroller method detailVC.navigationItem.leftBarButtonItem = [Uibarbuttonitem itemwithicon:@ "Btn_nav_close.png" highlightedicon:@ "Btn_nav_close_hl.png" target:self Action: @selector (HideDetail    )];    A data source is required to display data Detailvc.deal = deal in its internal xib generated from a child control; Use the navigation controller to wrap the real buy details controller Beyondnavigationcontroller *nav = [[Beyondnavigationcontroller alloc] Initwithrootviewcontrolle    R:DETAILVC]; To achieve the drawer effect of the detail controller, monitor pan gesture drag [Nav.view Addgesturerecognizer:[[uipangesturerecognizer alloc] initwithtarget:self action    : @selector (drag:)]; The detail controller is always on the right, so the left margin extendsShrinkage, height also telescopic nav.view.autoresizingMask = Uiviewautoresizingflexibleheight |    Uiviewautoresizingflexibleleftmargin; // ????    On the right side of the mask, it means that it is completely invisible, and then the animation moves slowly to the left??? Real detail controller with XIB package its height variable, but the width is generally to be fixed nav.view.frame = CGRectMake (_cover.frame.size.width, 0, Kdealdetailvcwidth, _cove    R.frame.size.height); When 2 controllers are parent-child, their view is also a parent-child relationship, because if you add only view and no controller, then the controller will be destroyed after this method call is complete, because it is a local variable [self.navigationController.view    AddSubview:nav.view];        [Self.navigationcontroller Addchildviewcontroller:nav];         The animation moves slowly to the left, showing the details of the controller [UIView animatewithduration:kdefaultanimduration animations:^{cgrect f = nav.view.frame;        F.origin.x-= Kdealdetailvcwidth;    Nav.view.frame = f; }];} #pragma mark Hide Details Controller-(void) hidedetail{//Gets the navigation controller that wraps the detail controller, animates its view uiviewcontroller *nav = [Self.navigationcontro    Ller.childviewcontrollers Lastobject];                [UIView animatewithduration:0.3 animations:^{//1. Hide cover _cover.alpha = 0; 2. Hide controller CGRect f = Nav.view.frame;        F.origin.x + = Kdealdetailvcwidth;    Nav.view.frame = f;                } completion:^ (BOOL finished) {[_cover Removefromsuperview];        [Nav.view Removefromsuperview];    [Nav Removefromparentviewcontroller]; }];} #pragma mark-Let the detail controller have drawer effect, plus spring effect-(void) Drag: (Uipangesturerecognizer *) pan{//left to negative cgfloat tx = [Pan Translationi    nview:pan.view].x;        At the end of the gesture, let go if (pan.state = = uigesturerecognizerstateended) {cgfloat HALFW = pan.view.frame.size.width * 0.5;        if (TX >= HALFW) {//has moved more than half to the right [self hidedetail]; } else {[UIView animatewithduration:kdefaultanimduration animations:^{pan.view.transform = CGA            ffinetransformidentity;        }];        }} else {//move the Controller's view if (TX < 0) {//to the left of TX *= 0.4;    } Pan.view.transform = cgaffinetransformmaketranslation (TX, 0); }} @end


Parent class Basedeallistcontroller

Responsible for creating and maintaining a collectionview, and totaldealsarr the data source to the subclass

  basedeallistcontroller.h//  Handsome _ buy////  Created by Beyond on 14-8-21.//  Copyright (c) 2014 Com.beyond. All rights reserved.//  is located in the middle layer of the parent class, inherited from the Showtdealdetailcontroller, automatically has a click on the xxx, as long as the supply of data sources, the animation display purchase details of the function, and automatically has a click to cover, animation hidden out of the group purchase details of the function of the controller .... own only responsible for the maintenance of a CollectionView (nine Gongge), and nine Gongge of the data source (Group purchase object array) to provide #import "ShowDealDetailController.h" by the subclass @interface basedeallistcontroller:showdealdetailcontroller{    Uicollectionview *_collectionview;} Nine Gongge data source (Group buy object array) provided by subclasses-(Nsarray *) totaldeals; All the group buy data @end

basedeallistcontroller.m//Handsome _ buy////Created by Beyond on 14-8-21.//Copyright (c) 2014 Com.beyond. All rights reserved.//is located in the middle layer of the parent class, inherited from Showtdealdetailcontroller, automatically has a click on the xxx, as long as the supply of data sources, on the animation display purchase details of the function, and automatically have a click cover, Animation hides the function of the buy details controller .... I am only responsible for establishing and maintaining a CollectionView (nine Gongge), and nine Gongge data sources (Group purchase object array) provide #import "BaseDealListController.h" #import "Deal.h" to subclasses themselves #import "DealCell.h"//each grid width and height # kitemw 250#define kitemh 250@interface basedeallistcontroller () < Uicollectionviewdatasource, uicollectionviewdelegate>//to create and maintain a nine Gongge, the data source (Group purchase object array) provides @property (Nonatomic, Strong) Uicollectionview *collectionview, @end @implementation basedeallistcontroller#pragma mark-life cycle Method-(void)        viewdidload{[Super Viewdidload];        1. Create your own CollectionView [self addcollectionview]; 2. xib file to be used for registering cell lattice [Self.collectionview registernib:[uinib nibwithnibname:@ "Dealcell" Bundle:nil]        forcellwithreuseidentifier:@ "Dealcell"]; 3. Set CollectionView to always support vertical scrolling, ready for pull-down refresh (Spring) self.collectionView.alwaysbouncevertical = YES; 4. Set the background color of the collectionview Self.collectionView.backgroundColor = KGLOBALBG;} 1. Create your own collectionview-(void) addcollectionview{//Create a flow layout, you must specify uicollectionviewflowlayout *layout = [[Uicollecti    Onviewflowlayout alloc] init];    Set the flow layout inside each grid width and height, that is, the size of each grid layout.itemsize = Cgsizemake (KITEMW, KITEMH);    The spacing between each line layout.minimumlinespacing = 20; Specify the flow layout to create a collectionview, and use member variables to remember self.collectionview = [[Uicollectionview alloc] InitWithFrame:self.view.bounds    Collectionviewlayout:layout]; Height and width auto-scaling self.collectionView.autoresizingMask = Uiviewautoresizingflexibleheight |    Uiviewautoresizingflexiblewidth;    Self.collectionView.delegate = self;    Self.collectionView.dataSource = self; [Self.view AddSubview:self.collectionView];} #pragma mark can get the most accurate width and height of the view in Viewwillappear and Viewdidappear//Important ~ ~ ~ because when the controller is created, the width default is 768, the high default is 1024, regardless of the screen// Only in the Viewwillappear and Viewdidappear methods can you get the view's most accurate (that is, the actual) width and height (width and height)-(void) ViewwilLappear: (BOOL) animated{//default calculation layout [self didrotatefrominterfaceorientation:0];} #pragma mark-parent method//intercept, call when screen is about to rotate (Controller monitor screen rotation)-(void) Willrotatetointerfaceorientation: (uiinterfaceorientation) Tointerfaceorientation Duration: (nstimeinterval) duration{//log (@ "screen is about to rotate");} #pragma mark screen is rotated at the end of the call//intercept, when screen rotation is complete call-(void) Didrotatefrominterfaceorientation: (uiinterfaceorientation)    frominterfaceorientation{//1. Remove the uicollectionviewflowlayout that was passed in when the Collectionviewcontroller was created            Uicollectionviewflowlayout *layout = (uicollectionviewflowlayout *) self.collectionView.collectionViewLayout;    2. Calculate the spacing CGFloat v = 0;    CGFloat h = 0;    CGFloat height = self.view.frame.size.height-44;    CGFloat width = self.view.frame.size.width; if (Uiinterfaceorientationislandscape (self.interfaceorientation)) {//cross-screen spacing v = (height-2 * KItem        H)/3;            H = (width-3 * kitemw)/4;        } else {//vertical screen spacing v = (height-3 * kitemh)/4;H = (Width-2 * kitemw)/3; }//3. Adjust the distance between the squares of the animation [UIView animatewithduration:4.0 animations:^{//Margin layout.section in the upper left and right four directions        Inset = Uiedgeinsetsmake (H, H, V, h);    The spacing between each line layout.minimumlinespacing = h; }];} #pragma Mark-collectionview Proxy method//Total number of item (that is, lattice cube), ask sub-class-(Nsinteger) CollectionView: (Uicollectionview *) CollectionView numberofitemsinsection: (nsinteger) section{return self.totalDeals.count;} #pragma mark is called when the data is refreshed (reloaddata) #pragma mark calls//generates each unique lattice whenever a cell re-enters the screen field of view, asking the subclass-(Uicollectionviewcell * ) CollectionView: (Uicollectionview *) CollectionView Cellforitematindexpath: (Nsindexpath *) indexPath{static NSString    *id = @ "Dealcell";        Dealcell *cell = [CollectionView dequeuereusablecellwithreuseidentifier:id Forindexpath:indexpath];        Cell.deal = Self.totaldeals[indexpath.row]; return cell;} When clicked on a lattice, showdealdetailvc-(void) CollectionView: (Uicollectionview *) CollectionView Didselectitematindexpath: ( NSINdexpath *) indexpath{//Call the parent class method again to show the Dealdetail controller [self showdetail:self.totaldeals[indexpath.row];} #pragma mark-life cycle Method-(void) dealloc{[[Nsnotificationcenter Defaultcenter] removeobserver:self];} @end

sub-class Deallistcontroller

Simply inherit and provide the data source to the parent class Totaldealsarr

  deallistcontroller.h//  Handsome _ buy////  Created by Beyond on 14-8-14.//  Copyright (c) 2014 Com.beyond. All Rights reserved.//  Click on the dock above the "buy" button corresponding to the controller, above the navigation bar, the right side of the navigation bar is Searchbar, the left side of the navigation bar is a large button (Topmenu) (the interior consists of three small buttons < topmenuitem>)//The controller inherits from Basedeallistcontroller, it automatically owns nine Gongge, only need to provide data for it, and Basedeallistcontroller inherited from SHOWDEALDETAILVC, has the function of showing leisure #import "BaseDealListController.h" @interface Deallistcontroller:basedeallistcontroller@end

deallistcontroller.m//Handsome _ buy////Created by Beyond on 14-8-14.//Copyright (c) 2014 Com.beyond. All rights reserved.//Click on the dock above the "buy" button corresponding to the controller, above the navigation bar, the right side of the navigation bar is Searchbar, the left side of the navigation bar is a large button (Topmenu) (the interior consists of three small buttons < topmenuitem>) #import "DealListController.h"//The left side of the navigation bar is a large button (top menu) #import "TopMenu.h"//Encapsulated Custom Cell#import " DealCell.h "//reviews provided encapsulation of sending request class #import" DPAPI.h "//Tool class #import" MetaDataTool.h "//Package Request Tool Class #import" DealRequestTool.h "// Model class #import "City.h" #import "Deal.h"//two-times package picture Download Tool class #import "ImgDownloadTool.h" #define KITEMW 250#define KITEMH 250@ Interface Deallistcontroller () <dprequestdelegate,mjrefreshbaseviewdelegate>{//used to receive the dictionary array returned by the server----converted to an array of objects,    For lattice show Nsmutablearray *_deals;    Drop-down refresh Mjrefreshheaderview *_header;    Pull-up loading next page Mjrefreshfooterview *_footer;    Number of pages per load int _pageno; } @end @implementation deallistcontroller//inherits the Basedeallistcontroller controller, the method that must be implemented to provide a data source for CollectionView-(Nsarray *) totaldeals{return _deals;} -(void) viewdidload{[Super ViewDidload];                    _deals = [Nsmutablearray array];        1. Basic settings for the top navigation bar [self setnavigationbar];        2. Add Refresh control [self addrefresher]; 0. Listen to the notice of the city change, on the drop-down refresh kaddallnotes (DataChange)}//0. Listen to the notice of city change, pull down refresh-(void) datachange{[_header beginrefreshing];    }//1. Basic settings for the top navigation bar-(void) setnavigationbar{//1. The search box on the right Uisearchbar *s = [[Uisearchbar alloc] init];    S.frame = CGRectMake (0, 0, 210, 35);    S.placeholder = @ "Please enter product name, address, etc.";        Self.navigationItem.rightBarButtonItem = [[Uibarbuttonitem alloc] initwithcustomview:s];    2. Left menu bar Topmenu *top = [[Topmenu alloc] init]; Important, Topmenu inside the item clicked, the created Popmenu will be added to where to go???    is the view Top.controllerview = Self.view of this controller;        Self.navigationItem.leftBarButtonItem = [[Uibarbuttonitem alloc] initwithcustomview:top];    }//3. Add Refresh Control-(void) addrefresher{_header = [Mjrefreshheaderview header];    _header.scrollview = _collectionview;        _header.delegate = self; _footer = [MjrefreshfooterviewFooter];    _footer.scrollview = _collectionview; _footer.delegate = self;} #pragma the agent method of the Mark Refresh Control-(void) refreshviewbeginrefreshing: (Mjrefreshbaseview *) refreshview{//mark it, pull or pull BOOL IsH    Eader = [Refreshview Iskindofclass:[mjrefreshheaderview class]];        if (IsHeader) {//drop-down refresh//suggest first, clear memory cache of previously downloaded pictures [Imgdownloadtool clear];    Each pull-down is loaded on the first page _pageno = 1;    } else {//pull up loads more, that is, load the next page _pageno++; }//Load data from page _pageno [[Dealrequesttool Shareddealrequesttool] Dealrequestwithpageno:_pageno success:^ (NSArray *d        Eals,int total_count) {if (IsHeader) {///if the first page of data is loaded as a pull-down, remove the old [_deals removeallobjects] first;                }//1. Add a new array of returned objects [_deals addobjectsfromarray:deals];                2. Refresh the table [_collectionview Reloaddata];                3. Restore refresh status [Refreshview endrefreshing];   4. According to the total number of simple to determine whether you need to hide the pull-up control _footer.hidden = _deals.count >= total_count;                 } fail:^ (Nserror *error) {log (@ "request failed--%@", error);    Also to hide [Refreshview endrefreshing]; }];} @end



IOS_21 Group Purchase _ Controller inheritance diagram

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.