iOS Project Love limit Waiver One

Source: Internet
Author: User

Project creation

1, access to the project related Materials, interface, interface material, as well as to get the network interface.

2, create the project, create some logical folders in the project, to store the corresponding files, clear display

introduction of afnetworking;

3, the design of each viewcontroller, the design of a number of interfaces are shown separately.

#import "RootViewController.h"#import "ApplistViewController.h"#import "HotViewController.h"#import "ScaleViewController.h"#import "TopicViewController.h"#import "FreeViewController.h"#import "LimitViewController.h"

4. Create Rootviewcontroller navigation bar and Tab bar (encapsulated during this process)

4.1 Inherits the Uiimageview category creation, facilitates the post-creation of multiple buttons, or multiple label

//Add System button-(UIButton *) Addsystembuttonwithframe: (CGRect) Frame title: (NSString *) title action: (void(^) (UIButton *button)) action{Jayzybutton*button =[Jayzybutton Buttonwithtype:uibuttontypesystem]; Button.frame=frame;        [Button Settitle:title forstate:uicontrolstatereserved]; Button.action=Action;    [Self Addsubview:button]; returnbutton;}//Add Picture button-(UIButton *) Addimagebuttonwithframe: (CGRect) Frame title: (NSString *) title background: (NSString *) Background action :(void(^) (UIButton *button)) action{Jayzybutton*button =[Jayzybutton Buttonwithtype:uibuttontypesystem]; Button.frame=frame;    [Button Settitle:title forstate:uicontrolstatereserved];    [Button Setbackgroundimage:[uiimage Imagenamed:background] forstate:uicontrolstatenormal]; Button.action=Action;    [Self Addsubview:button]; returnbutton; }//Add ImageView-(uiimageview*) Addimageviewwithframe: (CGRect) Frame Image: (NSString *) image{Uiimageview*imageview =[[Uiimageview alloc] initwithframe:frame]; Imageview.image=[UIImage Imagenamed:image]; Imageview.userinteractionenabled=YES;    [Self addsubview:imageview]; returnImageView;}//Add Tags-(UILabel *) Addlabelwithframe: (CGRect) frame text: (NSString *) text{UILabel*label =[[UILabel alloc] initwithframe:frame]; Label.text=text;    [Self Addsubview:label]; returnlabel;}

4.2 Need to create 5 views controlled by tag controller, unified encapsulation, incoming category, label title, label background picture

//quickly add an attempt to the controller-(Uiviewcontroller *) Addviewcontroller: (Class) CLS Title:(NSString *) title Image: (NSString *) image{//classes corresponding to the CLS incoming interfaceUiviewcontroller *VC =[[CLS Alloc] init]; Vc.title=title; Uinavigationcontroller*NC =[[Uinavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:VC]; Nc.tabBarItem.image=[UIImage Imagenamed:image]; //Add to labelNsmutablearray *marr =[[Nsmutablearray alloc] initWithArray:self.viewControllers];    [Marr ADDOBJECT:NC]; Self.viewcontrollers=Marr;//returns the attempted controller created    returnVC;}

4.3 Start setting the left and right buttons on the home navigation bar

[self Confignavigationbutton];#pragmaMark------Configure the navigation bar-(void) confignavigationbutton{//To Create multiple buttons, set multiple viewsUIButton *leftbutton =[UIButton Buttonwithtype:uibuttontypesystem]; Leftbutton.frame=cgrectmake (0,0, $, -); [LeftButton settitle:@"category"Forstate:uicontrolstatenormal]; [LeftButton setbackgroundimage:[uiimage imagenamed:@"Buttonbar_action.png"] Forstate:uicontrolstatenormal];    [LeftButton Settitlecolor:[uicolor Blackcolor] forstate:uicontrolstatenormal]; LeftButton.titleLabel.font=[uifont systemfontofsize:14.0f];    [LeftButton addtarget:self Action: @selector (Dealleftclick:) forcontrolevents:uicontroleventtouchupinside]; Uibarbuttonitem*leftitem =[[Uibarbuttonitem alloc] Initwithcustomview:leftbutton]; Self.navigationItem.leftBarButtonItem=Leftitem; //Add right navigationUIButton *rightbutton =[UIButton Buttonwithtype:uibuttontypesystem]; Rightbutton.frame=cgrectmake (0,0, $, -); [Rightbutton settitle:@"Set"Forstate:uicontrolstatenormal];    [Rightbutton Settitlecolor:[uicolor Blackcolor] forstate:uicontrolstatenormal]; [Rightbutton setbackgroundimage:[uiimage imagenamed:@"Buttonbar_action.png"] Forstate:uicontrolstatenormal]; RightButton.titleLabel.font=[uifont systemfontofsize:14.0f];    [Rightbutton addtarget:self Action: @selector (Dealrightclick:) forcontrolevents:uicontroleventtouchupinside]; Uibarbuttonitem*rightitem =[[Uibarbuttonitem alloc] Initwithcustomview:rightbutton]; Self.navigationItem.rightBarButtonItem=Rightitem;}

4.4 Download data for parsing, configure the UITableView of the page

_dataarray=[[Nsmutablearray alloc] init]; _page=1; _categoryid=@"";//"" In the URL interface means all[self startdownloaddata];============ ===============-(void) startdownloaddata{//download data, JSON parsingNSString *urlstring =[NSString Stringwithformat:limit_url,_page,_categoryid]; Afhttprequestoperationmanager*manager =[Afhttprequestoperationmanager Manager]; Manager.responseserializer=[Afhttpresponseserializer Serializer]; [Manager get:urlstring Parameters:nil success:^ (Afhttprequestoperation *operation,IDresponseobject) {        //parsing in JSON formatNsdictionary *dict =[nsjsonserialization jsonobjectwithdata:responseobject options:nsjsonreadingmutablecontainers Error:nil];//NSLog (@ "dict =%@", dict);Nsarray*applist = dict[@"Applications"];  for(Nsdictionary *appdictinchapplist) {           //The data model is created here first[Self creatmodelcodewithdictionary:appdict name:@"Appmodel"]; //KVC, if the key value does not have a corresponding property, it crashes. Appmodel *model =[[Appmodel alloc] init];             [Model Setvaluesforkeyswithdictionary:appdict]; Model.desc=appdict[@"Description"];        [_dataarray Addobject:model];            } [_tableview Reloaddata]; } Failure:^ (Afhttprequestoperation *operation, Nserror *error)   {            }]; }

4.5 Create a data model based on downloaded data analysis.

//Create the Model code, generate the code based on the dictionary-(void) Creatmodelcodewithdictionary: (nsdictionary *) dict name:(NSString *) name{printf ("\[email protected]%s:nsobject\n", name.    utf8string);  for(NSString *keyinchdict) {printf ("@property (copy,nonatomic) nsstring *%s;\n", key.    utf8string); } printf ("@end \ n");}============================================@interfaceAppmodel:nsobject@property (copy,nonatomic) NSString*Pricetrend, @property (copy,nonatomic) NSString*Expiredatetime, @property (copy,nonatomic) NSString*fileSize, @property (copy,nonatomic) NSString*CategoryName, @property (copy,nonatomic) NSString*IPA; @property (copy,nonatomic) NSString*Itunesurl, @property (copy,nonatomic) NSString*Name: @property (copy,nonatomic) NSString*version: @property (copy,nonatomic) NSString*Currentprice, @property (copy,nonatomic) NSString*starcurrent, @property (copy,nonatomic) NSString*Staroverall, @property (copy,nonatomic) NSString*Favorites, @property (copy,nonatomic) NSString*IconUrl, @property (copy,nonatomic) NSString*releasenotes, @property (copy,nonatomic) NSString*ReleaseDate, @property (copy,nonatomic) NSString*updatedate, @property (copy,nonatomic) NSString*Slug, @property (copy,nonatomic) NSString*downloads, @property (copy,nonatomic) NSString*Lastprice, @property (copy,nonatomic) NSString*Ratingoverall, @property (copy,nonatomic) NSString*ApplicationID, @property (copy,nonatomic) NSString*desc;//changed it.@property (copy,nonatomic) NSNumber*categoryid;//Modify@property (copy,nonatomic) NSString *shares;//Modify@end

4.6 Create UITableView, show data

#pragmaMark---Table view to display the data-(void) createtableview{_tableview=[[UITableView alloc] InitWithFrame:self.view.bounds Style:uitableviewstyleplain]; _tableview.datasource=Self ; _tableview.Delegate=Self ; [Self.view Addsubview:_tableview];}-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{return_dataarray.count;}-(CGFloat) TableView: (UITableView *) TableView Heightforrowatindexpath: (Nsindexpath *) indexpath{return  -;}-(uitableviewcell*) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{StaticNSString *cellid =@"Cell"; Appcell*cell =[TableView Dequeuereusablecellwithidentifier:cellid]; if(Cell = =Nil) {Cell=[[Appcell alloc] Initwithstyle:uitableviewcellstylesubtitle reuseidentifier:cellid]; } Appmodel*model =_dataarray[indexpath.row];//Cell.textLabel.text =model.name;[Cell.iconimageview Setimagewithurl:[nsurl URLWithString:model.iconUrl];//Cell.nameLable.text =model.name;Cell.nameLable.text =[nsstring stringWithFormat:@"%d.%@", indexpath.row+1, Model.name]; //Cell.priceLabel.text =model.lastprice;Cell.priceLabel.text =[nsstring stringWithFormat:@"¥%.2f", Model.lastPrice.doubleValue]; Cell.categoryLabel.text=Model.categoryname;    [Cell.starview SetStar:model.starCurrent.doubleValue]; Cell.shareLabel.text=[nsstring stringWithFormat:@"Share:%d", Model.shares.intValue]; Cell.favoriteLabel.text=[nsstring stringWithFormat:@"Favorites:%d", Model.favorites.intValue]; Cell.downloadLabel.text=[nsstring stringWithFormat:@"Download:%d", Model.downloads.intValue]; returncell; }

iOS Project Love limit Waiver One

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.