[iOS base Control-6.6] Show group purchase data customization Tableviewcell

Source: Internet
Author: User
Tags uikit

A. Requirements 1. Head AD 2. Custom cell: Contains picture, name, purchase quantity, Price 3. Use Xib to design custom cells, custom cells inherit from UITABLEVIEWCELL4. The tail "load more Buttons", and the data that is clicked after the load refresh, animation effect B. Implementation 1. Use MVCM: Buy Modelv: Total view, cell view (containing class and interface) C:viewcontroller 2. Classification Management code file 3. Tail footerview "load more" function
1     // Set up trailer controls 2     Self.tableView.tableFooterView = Footerview;
Footerview Set the button auto width to tableview width, only set the height; x and y cannot be set. To customize the button, use Xib to customize the Footerview nesting (1) using the button, design a "load more" button (2) plus the wait icon How to use Xib to encapsulate a view:
  • New Xib describes the structure of the view


  • Create a new class that inherits UIView (depending on the Xib root object's Class)
  • New class name, consistent with Xib
    @interface Footerrefreshview:uiview

  • Set the class of the Xib control, connect


  • Load class method for defining Xib in custom class (masking xib loading process)
    1 /** Initialization Method*/2+ (Instancetype) Footerrrefreshviewwithdelegate: (ID<FooterRefreshViewDelegate>)Delegate {3Footerrefreshview *footerrefreshview = [[[NSBundle Mainbundle] loadnibnamed:@"Footerrefreshview"Owner:nil Options:nil] lastobject];4    5     if(Nil! =Delegate) {6Footerrefreshview.Delegate=Delegate;7     }8    9     returnFooterrefreshview;Ten}
  • Class holds controller reference, sends a message to controller to refresh data
    Use proxy mode below
- Improved: Using proxy design mode
    • The class of the custom view holds a reference to the controller, and the use of a proxy with strong coupling
    • Protocol naming specification: control class name +delegate
    • Proxy methods are generally @optional
    • The proxy object follows the proxy protocol and implements the method inside the proxy protocol.
    • Call the proxy method where needed to send a message to the agent
1 FooterRefreshView.h2 #import<UIKit/UIKit.h>3 4 @classFooterrefreshview;5 6 //defining the Delegate protocol7 @protocolFooterrefreshviewdelegate <NSObject>8 9 @optionalTen- (void) Footerrefreshviewclickedfooterrefreshbutton: (Footerrefreshview *) Footerrefreshview; One  A @end -  - @interfaceFooterrefreshview:uiview the  -+ (Instancetype) Footerrrefreshviewwithdelegate: (ID<FooterRefreshViewDelegate>)Delegate; -  - @end
Instead of calling the Init method in class after the view created in 4.xib has been initialized, the Awakefromnib method is called FooterRefreshView.h
1 // Xib The initialization of the control call method 2 -(void) awakefromnib {3     self.loadingImage.hidden = YES; 4 }
5. Split line is actually a height of 1 uiview 6. Custom cell(1). The child controls of the custom cell are put into the Contentview. The default is to put it into Contentview (2) to create a class that inherits from UITableViewCell@interface Grouppurchasecell:uitableviewcell(3) Create a xib file to describe the cell interface (4) Specify the class of the view, connect the control (5) in the cell class, define a model member to store the cell's data
1 /*  */2 + (Instancetype) Grouppurchasecellwithgrouppurchase: (Grouppurchase *) grouppurchase;
(6) Create initialization method, use model data as incoming parameter
1 /** Custom initialized class method, incoming model data*/2+ (Instancetype) Grouppurchasecellwithgrouppurchase: (Grouppurchase *) Grouppurchase {3Grouppurchasecell *cell = [[[NSBundle Mainbundle] loadnibnamed:@"Grouppurchasecell"Owner:nil Options:nil] lastobject];4    5     //load the data in the model, initialize the interface6Cell.grouppurchase =grouppurchase;7    8     returncell;9 }Ten  One /** Empty cell without model data*/ A+(instancetype) Grouppurchasecell { -     return[self grouppurchasecellwithgrouppurchase:nil]; -}
(7) When the model data is passed in, load the data to the view
1 /** Load model data, initialize interface*/2- (void) Setgrouppurchase: (Grouppurchase *) Grouppurchase {3     if(Nil! =grouppurchase) {4Self.titleLabel.text =Grouppurchase.title;5Self.iconImageView.image =[UIImage ImageNamed:groupPurchase.icon];6Self.priceLabel.text = [NSString stringWithFormat:@"¥%@", Grouppurchase.price];7Self.buyCountLabel.text = [NSString stringWithFormat:@"%@ people have already purchased", Grouppurchase.buycount];8     }9    Ten_grouppurchase =grouppurchase; One}
7. The head ad is actually the previous scrolling ad put to Self.tableView.tableHeaderView (1) Design Interface (2) Create class load Picture data (3) An array of incoming picture names as members
1 // ad group 2 @property (nonatomic, strong) Nsarray *ads;
(4) Loading pictures
1 /** Set Ads*/2- (void) Setads: (Nsarray *) Ads {3     if(Nil! =ads) {4CGFloat adimagewidth =Ad_view_width;5CGFloat adimageheight =Ad_view_height;6CGFloat Adimagey =0;7        8          for(intI=0; i<ads.count; i++) {9             //calculates the horizontal coordinates of the current pictureTenCGFloat Adimagex = i *Adimagewidth; One             AUiimageview *adimageview =[[Uiimageview alloc] Initwithframe:cgrectmake (Adimagex, Adimagey, Adimagewidth, Adimageheight)]; -Adimageview.image = [UIImage imagenamed:[nsstring stringWithFormat:@"%@", Ads[i]]; -          the [Self.scrollview Addsubview:adimageview]; -         } -         -         //Set scrolling +Self.scrollView.contentSize = Cgsizemake (Ads.count * ad_view_width,0); -self.scrollView.scrollEnabled =YES; +     } A     at_ads =ads; -}
(5) in the master controller, set up the picture data, create the head control to add to the head position
1     // set up your head ad 2     // manually assemble your ad image data 3     Self.tableView.tableHeaderView = AdView;
(6) Adding page numbers and automatic carousel

[iOS base Control-6.6] Show group purchase data customization Tableviewcell

Related Article

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.