Cat learn iOS (13) UI UITableView Learning (bottom) car brand with right index

Source: Internet
Author: User

Cat Share, must boutique

Material code Address: http://blog.csdn.net/u013357243/article/details/44727225
Original address: Http://blog.csdn.net/u013357243?viewmode=contents

Look first.




Code Viewcontroller
//ps: New iOS Exchange Learning Group: 304570962Can add the cat cat QQ:1764541256Or Znycat Let's study hard together. Original: http://blog.csdn.net/u013357243?viewmode=contents//NYVIEWCONTROLLER.M//06-Auto brand with right index////Created by Apple on 15-3-29.//Copyright (c) 2015 Znycat. All rights reserved.//#Import "NYViewController.h"#Import "NYCarGroup.h"#Import "NYCar.h"@interfaceNyviewcontroller () <UITableViewDataSource>@property(Nonatomic, Strong) UITableView *tableview;@property(Nonatomic, Strong) Nsarray *cargroups;@end@implementationnyviewcontroller-(UITableView *) tableview{if(_tableview = = nil) {_tableview = [[UITableView alloc] InitWithFrame:self.view.bounds style:uitableviewstylegrouped];//Set data source_tableview.datasource = self;//Load up[Self.view Addsubview:_tableview]; }return_tableview;}//Lazy loading-(Nsarray *) cargroups{if(_cargroups = = nil)    {_cargroups = [nycargroup cargroups]; }return_cargroups;} - (void) viewdidload{[SuperViewdidload];//NSLog (@ "%@", self.cargroups);    //Call TableView Add to view[Self tableView];} #pragma mark-tableview Data source method/** Total number of groups * /-(Nsinteger) Numberofsectionsintableview: (UITableView *) tableview{returnSelf.carGroups.count;}/** How many rows each group, section is the group of * /-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{Nycargroup * Group = Self.cargroups[section];returnGroup.cars.count;}/** cell * /-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{//REUSABLE notation    StaticNSString *id = @"Cell";//Let the table go to buffer to find the reusable cellUITableViewCell * cell = [TableView dequeuereusablecellwithidentifier:id];//If a reusable cell is not found    if(cell = = nil) {//Instantiate cellcell = [[UITableViewCell alloc]initwithstyle:uitableviewcellstyledefault Reuseidentifier:id]; }//Set cell contents    //Remove Data ModelNycargroup *group = self.cargroups[indexpath.section]; Nycar *car = Group.cars[indexpath.row];//Set dataCell.imageView.image = [UIImage ImageNamed:car.icon]; Cell.textLabel.text = Car.name;returnCell;}/** The title of each group * /-(NSString *) TableView: (UITableView *) TableView titleforheaderinsection: (Nsinteger) section{return[Self.cargroups[section] title];}/** Right Index list * /-(Nsarray *) Sectionindextitlesfortableview: (UITableView *) tableview{/ * "Contents" in the indexed array, followed by the subscript in the group-Independent Index array, corresponding to the grouped subscript return @[@ "whoa haha", @ "Hello", @ "wow haha", @ "Hello", @ "wow haha", @ "Hello", @     "Wow haha", @ "Hello"];        Returns an array of title in Self.cargroup nsmutablearray *arraym = [Nsmutablearray array];        For (Hmcargroup *group in self.cargroups) {[Arraym addObject:group.title];     } return Arraym; KVC is Cocoa's big trick to indirectly get or modify the properties of an object using KVC when getting a numeric value, if the specified object does not contain the KeyPath "key Name", the object is automatically entered to find if the object is an array and returns an array as well * *    /* For example: nsarray *array = [self.cargroups valueforkeypath:@ "Cars.name"];    NSLog (@ "%@", array); */    return[Self.cargroups valueforkeypath:@"title"];}@end
Model Code

NYCar.h

////NYCar.h//06-Auto brand with right index////Created by Apple on 15-3-29.//Copyright (c) 2015 Znycat. All rights reserved.//#import <Foundation/Foundation.h>  @interface nycar : nsobject @property(nonatomic, copy)NSString*name;@property(nonatomic, copy)NSString*icon;-(Instancetype) Initwithdict: (nsdictionary*) dict;+ (instancetype) Carwithdict: (nsdictionary*) Dict;//Pass in an array containing a dictionary, returning an array of Hmcar models+(Nsarray*) Carswitharray: (Nsarray*) array;@end

Nycar.m

////NYCAR.M//06-Auto brand with right index////Created by Apple on 15-3-29.//Copyright (c) 2015 Znycat. All rights reserved.//#import "NYCar.h"  @implementation nycar -(Instancetype) Initwithdict: (nsdictionary*) dict{ Self= [SuperINIT];if( Self) {        [ SelfSETVALUESFORKEYSWITHDICTIONARY:DICT]; }return  Self;} + (Instancetype) Carwithdict: (nsdictionary*) dict{return[[ SelfAlloc] initwithdict:dict];} +(Nsarray*) Carswitharray: (Nsarray*) array{Nsmutablearray*arraym = [NsmutablearrayArray]; for(nsdictionary*dict in array) {[Arraym addobject:[ SelfCarwithdict:dict]]; }returnArraym;} - (NSString*) description{return[NSStringstringwithformat:@"<%@:%p> {name:%@, Icon:%@}", Self. Class, Self, Self. Name, Self. Icon];}@end

NYCarGroup.h

//  NYCarGroup.h  //06-Auto brand with right index  // //Created by Apple on 15-3-29.  //Copyright (c) 2015 Znycat. All rights reserved.  // #import  <foundation/foundation.h>< Span class= "hljs-annotation" > @interface  nycargroup:nsobject/** First letter */ Span class= "hljs-annotation" > @property  (nonatomic, copy) NSString *title; /** an array of cars, storing HMCAR model data */  @property  (Nonatomic, Strong) Nsarray *cars;-(Instancetype) initwithdict: (Nsdictionary *) dict;+ (instancetype) cargroupwithdict: (NSDictionary *) dict;+ (Nsarray *) cargroups;  @end   

nycargroup.m

////nycargroup.m//06-Auto brand with right index////Created by Apple on 15-3-29.//Copyright (c) 2015 Znycat. All rights reserved.//#import "NYCarGroup.h" #import "NYCar.h"  @implementation nycargroup -(Instancetype) Initwithdict: (nsdictionary*) dict{ Self= [SuperINIT];if( Self) {//[self setvaluesforkeyswithdictionary:dict];         //dict[@ "Cars"] is an array of dictionaries.        //Want to convert an array of dictionaries into an array of hmcar models        //[self setvalue:dict[@ "cars"] forkey:@ "Cars"];[ Selfsetvalue:dict[@"title"] forkeypath:@"title"]; Self. Cars= [Nycar carswitharray:dict[@"Cars"]]; }return  Self;} + (Instancetype) Cargroupwithdict: (nsdictionary*) dict{return[[ SelfAlloc] initwithdict:dict];} +(Nsarray*) cargroups{Nsarray*array = [Nsarrayarraywithcontentsoffile:[[NSBundlemainbundle]pathforresource:@"Cars_total.plist"OfType:Nil]];Nsmutablearray*arraym = [NsmutablearrayArray]; for(nsdictionary*dict in array) {[Arraym addobject:[ SelfCargroupwithdict:dict]]; }returnArraym;} - (NSString*) description{return[NSStringstringwithformat:@"<%@:%p> {title:%@, Cars:%@}", Self. Class, Self, Self. Title, Self. Cars];}@end

Code is a couple.

Watch out.

To implement the right index:

/* Right index list /
-(Nsarray ) Sectionindextitlesfortableview: (UITableView ) TableView

Review of DataSource

@required的两个/**单元格*/-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath/**每一组多少行 ,section是第几组*/-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

/* Total number of groups /
-(Nsinteger) Numberofsectionsintableview: (UITableView *) TableView

/* Title of each group /
-(NSString ) TableView: (UITableView ) TableView titleforheaderinsection: (nsinteger) Section

Wrong, help failed [Apple MACH-O linker ERROR]

I heard that learning iOS Baidu is useless ... Today, it's a mistake.
"Apple MACH-O linker error"

Degrees Niang N Long, asked 8 iOS-related learning groups, get no outside of this
{
Common Error Descriptions:
The last line of error messages for Apple Mach-o Linker error is usually as follows:
Command/developer/platforms/iphoneos.platform/developer/usr/bin/clang failed with exit code 1
This error is usually caused by a link error in the project that has the same name as the class.

It's possible that you have two class names all the same, or because you defined the same const variable in a different. m file.

This type of error requires you to look at the long string of paths given in the error message to find out the name of your duplicate class or variable to locate the wrong location.
}

好了 我只想说,猫猫自己把代码拷贝出来,然后又关了xcode ,最后重新建立了一个项目,把代码不动得放回,就这么华丽丽的好了。。。。。。。。。。。。

(I have a microphone)
iOS This part needs us all to work together Ah!
!!! Share our success, Meow.

PS: New iOS Exchange Learning Group: 304570962
You can add a cat qq:1764541256 or Znycat.
Let's study hard together.
Original: Http://blog.csdn.net/u013357243?viewmode=contents

Cat learn iOS (13) UI UITableView Learning (bottom) car brand with right index

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.