[Basic iOS control and basic ios Control

Source: Internet
Author: User

[Basic iOS control and basic ios Control
A. requirement 1. head Advertisement 2. custom cell: contains pictures, names, quantity, and price. use xib to design custom cells. Custom cells inherit from uitableviewcell4. "load more buttons" at the end ", and the data loading and refreshing after it is clicked, animation effect 1 // set the tail control 2 self. tableView. tableFooterView = footerView;1/** Initialization Method */2 + (instancetype) initialize :( id <FooterRefreshViewDelegate>) delegate {3 FooterRefreshView * footerRefreshView = [[NSBundle mainBundle] loadNibNamed: @ "FooterRefreshView" owner: nil options: nil] lastObject]; 4 5 if (nil! = Delegate) {6 footerRefreshView. delegate = delegate; 7} 8 9 return footerRefreshView; 10}

  • Class holds the controller reference and sends a message to the controller to refresh the data.
    The following uses the proxy mode.
  • -> Improvement: Use the proxy Design Mode
    • The class of the custom view holds the reference of the controller, and the coupling is strong-> use the proxy
    • Protocol naming rules: control class name + Delegate
    • Common proxy methods are @ optional.
    • The proxy object complies with the proxy Protocol to implement the methods in the proxy protocol.
    • Call the proxy method as needed to send messages to the proxy
    1 FooterRefreshView. h 2 # import <UIKit/UIKit. h> 3 4 @ class FooterRefreshView; 5 6 // define the delegate protocol 7 @ protocol FooterRefreshViewDelegate <NSObject> 8 9 @ optional10-(void) Authorization :( FooterRefreshView *) footerRefreshView; 11 12 @ end13 14 @ interface FooterRefreshView: UIView15 16 + (instancetype) footerRrefreshViewWithDelegate :( id <FooterRefreshViewDelegate>) delegate; 17 18 @ end
    4. The view created in xib does not call the init method in class after initialization, but calls the awakeFromNib method FooterRefreshView. h
    1 // method of calling the initialization of the xib Control 2-(void) awakeFromNib {3 self. loadingImage. hidden = YES; 4}
    5. The split line is actually a UIView with a height of 1. 6. Custom cell(1 ). the sub-control of the custom cell should be placed in contentView. By default, it will be placed in contentView. @ interface GroupPurchaseCell: UITableViewCell (3) create an xib file to describe the cell interface 1/** custom initialization class method, and pass in the model data */2 + (instancetype) groupPurchaseCellWithGroupPurchase :( GroupPurchase *) groupPurchase;(6) Create an initialization method and use model data as input parameters.
    1/** custom initialization class method, input model data */2 + (instancetype) usage :( GroupPurchase *) groupPurchase {3 GroupPurchaseCell * cell = [[NSBundle mainBundle] loadNibNamed: @ "GroupPurchaseCell" owner: nil options: nil] lastObject]; 4 5 // load data in the model, initialize interface 6 cell. groupPurchase = groupPurchase; 7 8 return cell; 9} 10 11/** empty cell without model data */12 + (instancetype) groupPurchaseCell {13 return [self failed: nil]; 14}
    (7) load the data to the view while passing in the model data
    1/** load Model data, initialization interface */2-(void) setGroupPurchase :( GroupPurchase *) groupPurchase {3 if (nil! = GroupPurchase) {4 self. titleLabel. text = groupPurchase. title; 5 self. iconImageView. image = [UIImage imageNamed: groupPurchase. icon]; 6 self. priceLabel. text = [NSString stringWithFormat: @ "¥ % @", groupPurchase. price]; 7 self. buyCountLabel. text = [NSString stringWithFormat: @ "% @ has been purchased", groupPurchase. buyCount]; 8} 9 10 _ groupPurchase = groupPurchase; 11}
    7. The first advertisement is actually the previous rolling advertisement placed in self. tableView. tableHeaderView (1) Design Interface 1 // ad group 2 @ property (nonatomic, strong) NSArray * ads;(4) Attach Images
    1/** set ads */2-(void) setAds :( NSArray *) ads {3 if (nil! = Ads) {4 CGFloat adImageWidth = AD_VIEW_WIDTH; 5 CGFloat adImageHeight = AD_VIEW_HEIGHT; 6 CGFloat adImageY = 0; 7 8 for (int I = 0; I <ads. count; I ++) {9 // calculate the horizontal coordinate of the current image 10 CGFloat adImageX = I * adImageWidth; 11 12 UIImageView * adImageView = [[UIImageView alloc] initWithFrame: CGRectMake (adImageX, adImageY, adImageWidth, adImageHeight)]; 13 adImageView. image = [UIImage imageNamed: [NSString stringWithFormat: @ "% @", ads [I]; 14 15 [self. scrollView addSubview: adImageView]; 16} 17 18 // set to scroll 19 self. scrollView. contentSize = CGSizeMake (ads. count * AD_VIEW_WIDTH, 0); 20 self. scrollView. scrollEnabled = YES; 21} 22 23 _ ads = ads; 24}
    (5) On the master controller, set the image data and create a header control to add it to the header position.
    1 // set the header Ad 2 HeaderAdView * adView = [self genAdView]; // manually assemble the ad image data 3 self. tableView. tableHeaderView = adView;
    (6) add page numbers and automatic carousel

    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.