iOS basic control display group purchase data UITableViewCell < agent, Xib package view>

Source: Internet
Author: User

1. Main controller:
  1//2//VIEWCONTROLLER.M 3//Grouppurchase 4//5//Created by Hellovoidworld on 14/12/3. 6//Copyright (c) 2014 Hellovoidworld.  All rights reserved. 7//8 9 #import "ViewController.h" #import "GroupPurchase.h" #import "GroupPurchaseCell.h" #import "Footerref ReshView.h "#import" HeaderAdView.h "@interface Viewcontroller () <FooterRefreshViewDelegate> 17 18 @ Property (Nonatomic, Strong) Nsarray *grouppurchases; @end @implementation Viewcontroller-(void) viewdidload {[Super Viewdidload]; +//Do an Y additional setup after loading the view, typically from a nib. 27 28//Create tail control Footerrefreshview *footerview = [Footerrefreshview footerrrefreshviewwithdelegate:self]; 30 31//Set tail control Self.tableView.tableFooterView = Footerview; 33 34 35//Set head ad Headeradview *adview = [self genadview]; Manually assemble the image data of the advertisement PNS Self.tableView.tableHeaderView = AdView; 38} 39 40-(void) didreceivememorywarning {[Super didreceivememorywarning];/Dispose of any of the resources that can be r Ecreated. * #pragma mark-Status column-(BOOL) Prefersstatusbarhidden {~ ~ YES; #pragma mark-Data method 52/** delay Data load to model */Nsarray-(*) grouppurchases {(nil = = _grouppurchases) {Nsarray *dictarra y = [Nsarray arraywithcontentsoffile:[[nsbundle mainbundle] pathforresource:@ "Tgs.plist" OfType:nil]]; Nsmutablearray *mdictarray = [Nsmutablearray array]; Nsdictionary *dict in Dictarray) {grouppurchase *grouppurchase = [Grouppurchase grouppurch ASEWITHDICTIONARY:DICT]; [Mdictarray Addobject:grouppurchase]; _grouppurchases = Mdictarray; Up to _grouppurchases; /** (Nsinteger) Numberofsectionsintableview: (UITableView *) TableView {1}, 72} 7 3 74/** Number of rows */(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) Section {return Self.group Purchases.count; 77} 78 79/** content */-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Inde XPath {81 82//1. Create cell Grouppurchasecell *cell = [Grouppurchasecell grouppurchasecellwithtableview:self. TableView]; 84 85//2. Transfer model data to cell cell.grouppurchase = Self.grouppurchases[indexpath.row]; The return cell; 89} 90 91/** line High * * (cgfloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) Indexpath { return 80; 94} 95 96/** implement Footerrefreshviewdelegate protocol */-(void) Footerrefreshviewclickedfooterrefreshbutton: ( Footerrefreshview *) Footerrefreshview {98//Increase group purchase record grouppurchase *grouppurchase = [Grouppurchase grouppurchase ];100 Grouppurchase.icon = @ "m2mini.jpg"; 101 Grouppurchase.title = @ "Add use case"; 102 Grouppurchase.price = @ "88 "; 103 Grouppurchase.buycount = @" 32 "; 104 105//Add new data 106 Nsmutablearray *marray = [Nsmutablearray arraywit harray:self.grouppurchases];107 [Marray addobject:grouppurchase];108 self.grouppurchases = marray;109 110/ /Refresh Data 111 [Self.tableview reloaddata];112}113 114//Configure some head ads for data-(Headeradview *) Genadview {$ headeradvie W *adview = [Headeradview headeradview];117 118 Nsmutablearray *adimages = [Nsmutablearray array];119 for (int i=0; i<5; i++) {adimages addobject:[nsstring stringwithformat:@ "ad_%02d", i]];121}122 123 adview.ads = AdIm ages;124 return adview;126}127 @end
2. Custom cell
 1//2//GROUPPURCHASECELL.M 3//Grouppurchase 4//5//Created by Hellovoidworld on 14/12/3. 6//Copyright (c) 2014 Hellovoidworld. All rights reserved. 7//8 9 #import "GroupPurchaseCell.h" #import "GroupPurchase.h" @implementation GroupPurchaseCell13 14//interface initialized When calling AwakeFromNib15-(void) awakefromnib {//initialization code17}18-(void) setselected: (BOOL) Selected Animat Ed: (BOOL) animated {[Super setselected:selected animated:animated];21//Configure The view for the selected     State23}24 25/** Custom initialized class method, incoming model data */26 + (Instancetype) Grouppurchasecellwithtableview: (UITableView *) TableView {27 NSString *id = @ "Grouppurchase"; 29 30//Search from cache pool Grouppurchasecell *cell = [TableView dequeu EREUSABLECELLWITHIDENTIFIER:ID];32 33//If the cache pool does not, create a if (nil = = cell) {+ = [[] [[NSBundle Mainbun DLE] loadnibnamed:@ "Grouppurchasecell" Owner:nil Options:nil] lastobject];36}37-Return cell;39}40 41/** Load model data, initialize interface */42-(void) Setgrouppurchase: (Grouppurchase *) grouppurchase {if (Nil! = Grouppur Chase) {Self.titleLabel.text = grouppurchase.title;45 self.iconImageView.image = [UIImage imagenamed:gr ouppurchase.icon];46 Self.priceLabel.text = [NSString stringwithformat:@ "¥%@", grouppurchase.price];47 sel F.buycountlabel.text = [NSString stringwithformat:@ "%@ people have purchased", grouppurchase.buycount];48}49   = grouppurchase;51}52 @end54
3. Bottom Load button
1//2//  FooterRefreshView.h 3//  Grouppurchase 4//5//  Created by Hellovoidworld on 14/12/3.6//  Copy Right (c) 2014 Hellovoidworld. All rights reserved. 7//8  9 #import <uikit/uikit.h>10 @class footerrefreshview;12 13//define Delegate protocol @protocol Footerrefreshvi Ewdelegate <nsobject>15 @optional17-(void) Footerrefreshviewclickedfooterrefreshbutton: (Footerrefreshview *) footerrefreshview;18 @end20 @interface footerrefreshview:uiview22 23//With proxy initialization method (Instancetype) Footerrref Reshviewwithdelegate: (id<footerrefreshviewdelegate>) delegate;25 @end

 1//2//FOOTERREFRESHVIEW.M 3//Grouppurchase 4//5//Created by Hellovoidworld on 14/12/3. 6//Copyright (c) 2014 Hellovoidworld. All rights reserved. 7//8 9 #import "load more" button at the bottom of "FooterRefreshView.h" @interface Footerrefreshview () 12/** */13 @property (weak, Nonato MIC) Iboutlet UIButton *footerrefreshbutton;14 15/** Load animation icon */16 @property (weak, nonatomic) Iboutlet Uiactivityindicator View *loadingimage;17 18/** agent */19 @property (nonatomic, weak) id<footerrefreshviewdelegate> delegate;20 21/** "load  More "button click event */22-(ibaction) onfooterrefreshbuttonclicked;23 @end26 @implementation FooterRefreshView28 #pragma Mark-Initialize 30 31/** Initialization Method */32 + (Instancetype) Footerrrefreshviewwithdelegate: (id<footerrefreshviewdelegate>) del egate {Footerrefreshview *footerrefreshview = [[[NSBundle Mainbundle] loadnibnamed:@ "Footerrefreshview" Owner:nil o Ptions:nil] lastobject];34 if (nil! = delegate) {footerrefreshview.delegate = Delegate;37}38-Footerrefreshview;40}41 The initialization method of the Xib control (void) awakefromnib {Self.loadingimag     E.hidden = yes;45}46 #pragma mark-action49/** "Load More" button click event */50-(ibaction) onfooterrefreshbuttonclicked {51  NSString *footerbuttontitle = self.footerrefreshbutton.currenttitle;52 53//Display loading the Self.loadingImage.hidden     = no;55 [Self.footerrefreshbutton settitle:@ "desperately loading ..." forstate:uicontrolstatenormal];56 57//Temporary Disable button event 58 self.footerRefreshButton.userInteractionEnabled = no;59 60//Analog delay of Dispatch_after (Dispatch_time (dispatch_time _now, (int64_t) (1.0 * nsec_per_sec)), Dispatch_get_main_queue (), ^{62//notify the agent that a click event occurred ([Self.delegate Respondstoselector: @selector (Footerrefreshviewclickedfooterrefreshbutton:)]) {[Self.delegate FOOTERREFRESHV IEWCLICKEDFOOTERREFRESHBUTTON:SELF];65}66 67//Restore button status Self.footerRefreshButton.userInte ractionenabled = yes;69        Self.loadingImage.hidden = yes;70 [Self.footerrefreshbutton settitle:footerbuttontitle Forstate:uicontrols TATENORMAL];71});}74 @end
4. Head Ads
1//2//  HeaderAdView.h 3//  Grouppurchase 4//5//  Created by Hellovoidworld on 14/12/3.6//  Copyright (c) Hellovoidworld 2014. All rights reserved. 7//8  9 #import <uikit/uikit.h>10 @interface HEADERADVIEW:UIVIEW12//ad group @property (nonatomic, Strong) N Sarray *ads;14 (instancetype) headeradview;16 @end
  1//2//HEADERADVIEW.M 3//Grouppurchase 4//5//Created by Hellovoidworld on 14/12/3. 6//Copyright (c) 2014 Hellovoidworld.  All rights reserved. 7//8 9 #import "HeaderAdView.h" #define AD_VIEW_WIDTH #define AD_VIEW_HEIGHT 120 13 14//Compliance Uiscrollvi Ewdelegate Monitoring scrolling Events @interface Headeradview () <UIScrollViewDelegate>/** scrollview Controls */@property (weak, nonatomic) Iboutlet Uiscrollview *scrollview; 19 20/** Page */@property (weak, nonatomic) Iboutlet Uipagecontrol *pagecontrol; 22 23/** Timer */@property (nonatomic, weak) Nstimer *timer; @end @implementation Headeradview #pragma mark-initialization method 31//Initialize Headeradview + (instancetype) head  Eradview {[NSBundle mainbundle] loadnibnamed:@ "Headeradview" Owner:nil Options:nil] lastobject]; 34} 35 36//When the control initializes the PNS from the nib-(void) awakefromnib {self.scrollView.scrollEnabled = YES;//Turn on scrolling self.scrollView.pag ingenabled = YES; Turn on Paging Mode 40 self.scrollView.delegate = self;//Set Agent 41} 42 43/** Set ADS */-(void) Setads: (Nsarray *) ads {(nil) ! = ads) {CGFloat adimagewidth = ad_view_width; CGFloat adimageheight = Ad_view_height; Gfloat adimagey = 0;  (int i=0; i<ads.count; i++) {51//calculates the horizontal coordinates of the current picture, cgfloat Adimagex = I * adimagewidth;  Uiimageview *adimageview = [[Uiimageview alloc] Initwithframe:cgrectmake (Adimagex, Adimagey, Adimagewidth, Adimageheight)]; Adimageview.image = [UIImage imagenamed:[nsstring stringwithformat:@ "%@", Ads[i]]; [Self.scrollview Addsubview:adimageview]; 58} 59 60//Set Scroll range self.scrollView.contentSize = Cgsizemake (Ads.count * ad_view_width , 0); Self.pageControl.numberOfPages = Ads.count; Total pages Self.pageControl.pageIndicatorTintColor = [Uicolor BlackcoloR]; Other page color self.pageControl.currentPageIndicatorTintColor = [Uicolor Redcolor]; Current Page Color 66 67//Add auto-carousel [self addtimer]; _ads = ads;  The #pragma mark-scrolling event 75//scrolling motion monitoring, when scrolling over half of the picture changes the page number (void) Scrollviewdidscroll: (Uiscrollview *) ScrollView { CGFloat scrollviewwidth = self.scrollView.frame.size.width; an int page = (self.scrollview.contentoffset.x + 0.5 * scrollviewwidth)/scrollviewwidth; self.pageControl.currentPage = page; 80} 81 82//Manual Drag ad Picture when Carousel, temporarily destroy automatic carousel-(void) scrollviewwillbegindragging: (Uiscrollview *) ScrollView {[self.ti Mer invalidate]; Self.timer = nil; 86} 87 88//Manual drag end, new plus automatic carousel-(void) scrollviewwillenddragging: (Uiscrollview *) ScrollView withvelocity: (cgpoint) vel Ocity targetcontentoffset: (inout cgpoint *) targetcontentoffset {[self AddTimer]; 91} 92 93//Add Timer 94-(void) AddTimer {self.timer = [Nstimer scheduledtimerwithtimeinterval:2.0 target:self selector: @selector (nextimage) Userinfo:nil Repeats:yes]; 96 97//Timer share main thread resource 98 [[Nsrunloop Currentrunloop] AddTimer:self.timer formode:nsrunloopcommonmodes]; 99}100 101//Next Picture Action 102-(void) nextimage {103 int page = 0;104//If the current page number is on the last page, from the new back to the first page, if (Self.pagecon Trol.currentpage = = self.ads.count-1) {106 page = 0;107}108 else {109 page = Self.pagecontrol.c Urrentpage + 1;110}111 112//scrolling picture, driving the picture effect 113 [Self.scrollview setcontentoffset:cgpointmake (Page * ad_view_w Idth, 0) animated:yes];114}115 @end
5.model
1//2//  GroupPurchase.h 3//  Grouppurchase 4//5//  Created by Hellovoidworld on 14/12/3.6//  Copyrigh T (c) 2014 Hellovoidworld. All rights reserved. 7//8  9 #import <foundation/foundation.h>10 @interface grouppurchase:nsobject12 13/** picture */14 @property (n onatomic, copy) nsstring *icon;15 16/** title */17 @property (nonatomic, copy) NSString *title;18 19/** has been purchased */20 @propert Y (nonatomic, copy) nsstring *buycount;21 22/** Price */23 @property (nonatomic, copy) NSString *price;24 25//initialization Method-(Inst Ancetype) Initwithdictionary: (Nsdictionary *) dictionary;27 + (Instancetype) Grouppurchasewithdictionary: ( Nsdictionary *) dictionary;28 + (instancetype) grouppurchase;29 @end
1//2//  GROUPPURCHASE.M 3//  Grouppurchase 4//5//  Created by Hellovoidworld on 14/12/3.6//  Copyrigh T (c) 2014 Hellovoidworld. All rights reserved. 7//8  9 #import "GroupPurchase.h" @implementation GroupPurchase12 13//initialization Method-(Instancetype) Initwithdictiona RY: (nsdictionary *) dictionary15 {     if (self = [super init]) {         //use KVC18         [self setvaluesforkeyswithdictionary:dictionary];19     }20     return self;22}23 + (instancetype) Grouppurchasewithdictionary: (nsdictionary *) dictionary {     return [[Self alloc] initwithdictionary:dictionary] ;}27 + (Instancetype) grouppurchase {     return [self grouppurchasewithdictionary:nil];30}31 @end
6.PLIST file Structure

iOS basic control display group purchase data UITableViewCell < agent, Xib package view>

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.