ios-Automotive Brand App

Source: Internet
Author: User

Information: Car pictures and plist

Files: Two models

////Car.h//Automotive Brands////Created by Yaguangzhu on 15/8/16.//Copyright (c) 2015 Yaguangzhu. All rights reserved.//#import<Foundation/Foundation.h>@interfaceCar:nsobject@property (nonatomic,copy) NSString*Name: @property (nonatomic,copy) NSString*icon;-(Instancetype) Initwithdict: (Nsdictionary *) dict;+ (Instancetype) carwithdict: (Nsdictionary *) dict;+ (Nsarray *) Carswitharray: (Nsarray *) array;@end
////CAR.M//Automotive Brands////Created by Yaguangzhu on 15/8/16.//Copyright (c) 2015 Yaguangzhu. All rights reserved.//#import "Car.h"@implementationCar-(Instancetype) Initwithdict: (Nsdictionary *) dict{ Self=[Super Init]; if(self) {[self setvaluesforkeyswithdictionary:dict]; }    returnSelf ;}+ (Instancetype) carwithdict: (Nsdictionary *) dict{return[Self alloc] initwithdict:dict];}+ (Nsarray *) Carswitharray: (Nsarray *) array{//Nsarray *array = [Nsarray arraywithcontentsoffile:[[nsbundle mainbundle] pathforresource:@ "Heros.plist" OfType: Nil]];Nsmutablearray *arraym =[Nsmutablearray array];  for(Nsdictionary *dictinchArray)    {[Arraym addobject:[self carwithdict:dict]]; }        returnArraym;}@end
////cargroup.m//Automotive Brands////Created by Yaguangzhu on 15/8/16.//Copyright (c) 2015 Yaguangzhu. All rights reserved.//#import "CarGroup.h"#import "Car.h"@implementationCargroup-(Instancetype) Initwithdict: (Nsdictionary *) dict{ Self=[Super Init]; if(self) {//[self setvaluesforkeyswithdictionary:dict];[Self setvalue:dict[@"title"] Forkey:@"title"]; Self.cars= [Car carswitharray:dict[@"Cars"]]; }    returnSelf ;}+ (Instancetype) cargroupwithdict: (Nsdictionary *) dict{return[Self alloc] initwithdict:dict];}+ (Nsarray *) cargroups1{Nsarray*array = [Nsarray arraywithcontentsoffile:[[nsbundle mainbundle] Pathforresource:@"cars_total.plist"Oftype:nil]]; Nsmutablearray*arraym =[Nsmutablearray array];  for(Nsdictionary *dictinchArray)    {[Arraym addobject:[self cargroupwithdict:dict]]; }        returnArraym;}@end
////CarGroup.h//Automotive Brands////Created by Yaguangzhu on 15/8/16.//Copyright (c) 2015 Yaguangzhu. All rights reserved.//#import<Foundation/Foundation.h>@interfaceCargroup:nsobject@property (nonatomic,copy) NSString*title: @property (nonatomic,strong) Nsarray*cars;-(Instancetype) Initwithdict: (Nsdictionary *) dict;+ (Instancetype) cargroupwithdict: (Nsdictionary *) dict;+ (Nsarray *) CarGroups1;@end
////VIEWCONTROLLER.M//Automotive Brands////Created by Yaguangzhu on 15/8/16.//Copyright (c) 2015 Yaguangzhu. All rights reserved.//#import "ViewController.h"#import "CarGroup.h"#import "Car.h"@interfaceViewcontroller () <UITableViewDataSource>@property (nonatomic,strong) Nsarray*CarGroups1, @property (nonatomic,strong) UITableView*TableView;@end@implementationViewcontroller-(UITableView *) tableview{if(_tableview = =Nil) {_tableview=[[UITableView alloc] InitWithFrame:self.view.bounds Style:uitableviewstyleplain]; _tableview.datasource=Self ;    [Self.view Addsubview:_tableview]; }    return_tableview;}-(Nsarray *) cargroups1{if(_cargroups1 = =Nil) {_CARGROUPS1=[Cargroup CARGROUPS1]; }        return_cargroups1;}- (void) viewdidload {[Super viewdidload]; //NSLog (@ "%@", SELF.CARGROUPS1);[self tableView]; //additional setup after loading the view, typically from a nib.}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}//Data Source Methods//total number of groupings-(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview{returnSelf.carGroups1.count;}//total for each group-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{Cargroup*group =Self.cargroups1[section]; returnGroup.cars.count;}//Cell Cell-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{StaticNSString *id =@"Cell"; UITableViewCell*cell =[TableView Dequeuereusablecellwithidentifier:id]; if(Cell = =Nil) {Cell=[[UITableViewCell alloc] Initwithstyle:uitableviewcellstyledefault Reuseidentifier:id]; } Cargroup*group =Self.cargroups1[indexpath.section]; Car*car =Group.cars[indexpath.row]; Cell.imageView.image=[UIImage ImageNamed:car.icon]; Cell.textLabel.text=Car.name; returncell;}//title-(NSString *) TableView: (UITableView *) TableView titleforfooterinsection: (nsinteger) section{Cargroup*group =Self.cargroups1[section]; returnGroup.title;}//Right Index list-(Nsarray *) Sectionindextitlesfortableview: (UITableView *) tableview{/*Nsmutablearray *arraym = [Nsmutablearray array];    For (Cargroup *group in Self.cargroups1) {[Arraym addObject:group.title]; } return Arraym;*/            //KVC is Cocoa's big trick.        return[Self.cargroups1 Valueforkeypath:@"title"];}@end

ios-Automotive Brand App

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.