Material: Photo gallery and plist of a hero profile
File: A Hero Data encapsulated module
////Hero.h//multiple sets of tables////Created by Yaguangzhu on 15/8/13.//Copyright (c) 2015 Yaguangzhu. All rights reserved.//#import<Foundation/Foundation.h>@interfaceHero:nsobject@property (nonatomic,copy) NSString*Name: @property (nonatomic,copy) NSString*icon; @property (nonatomic,copy) NSString*intro;-(Instancetype) Initwithdict: (Nsdictionary *) dict;+ (Instancetype) herowithdict: (Nsdictionary *) dict;+ (Nsarray *) heros;@end
////HERO.M//multiple sets of tables////Created by Yaguangzhu on 15/8/13.//Copyright (c) 2015 Yaguangzhu. All rights reserved.//#import "Hero.h"@implementationHero-(Instancetype) Initwithdict: (Nsdictionary *) dict{ Self=[Super Init]; if(self) {[self setvaluesforkeyswithdictionary:dict]; } returnSelf ;}+ (Instancetype) herowithdict: (Nsdictionary *) dict{return[Self alloc] initwithdict:dict];}+ (Nsarray *) heros{Nsarray*array = [Nsarray arraywithcontentsoffile:[[nsbundle mainbundle] Pathforresource:@"heros.plist"Oftype:nil]]; Nsmutablearray*arraym =[Nsmutablearray array]; for(Nsdictionary *dictinchArray) {[Arraym addobject:[self herowithdict:dict]]; } returnArraym;}@end
Main file:
////VIEWCONTROLLER.M//multiple sets of tables////Created by Yaguangzhu on 15/8/13.//Copyright (c) 2015 Yaguangzhu. All rights reserved.//#import "ViewController.h"#import "Hero.h"@interfaceViewcontroller () <UITableViewDataSource,UITableViewDelegate>@property (nonatomic,strong) UITableView*TableView, @property (nonatomic,strong) Nsarray*heros;@end@implementationViewcontroller-(Nsarray *) heros{if(_heros = =Nil) {_heros=[Hero heros]; } return_heros;}-(UITableView *) tableview{if(_tableview = =Nil) {_tableview=[[UITableView alloc]initwithframe:self.view.bounds Style:uitableviewstyleplain]; _tableview.datasource=Self ; [Self.view Addsubview:_tableview]; } return_tableview;}- (void) viewdidload {[Super viewdidload]; [Self tableView]; Self.tableView.rowHeight= the; Self.tableView.separatorStyle=Uitableviewcellseparatorstylesingleline; UIView*head = [[UIView alloc] Initwithframe:cgrectmake (0,0, the, -)]; Head.backgroundcolor=[Uicolor Redcolor]; Self.tableView.tableHeaderView=Head; UIView*foot = [[UIView alloc] Initwithframe:cgrectmake (0,0, the, -)]; Foot.backgroundcolor=[Uicolor Redcolor]; //Foot do refresh head advertisingSelf.tableView.tableFooterView =Foot; //additional setup after loading the view, typically from a nib.}-(Nsinteger) TableView: (UITableView *) TableView numberofrowsinsection: (nsinteger) section{returnSelf.heros.count;}-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) indexpath{//in order to join the cache pool, change the code below to rewrite//UITableViewCell *cell = [[UITableViewCell alloc] Initwithstyle:uitableviewcellstylesubtitle ReuseIdentifier:nil] ;//static variables ensure that the system allocates only one memory space for the variable in memory, but cannot create too many, because it will not be released and will only be released if the program is destroyed. StaticNSString *id =@"Cell"; UITableViewCell*cell =[TableView Dequeuereusablecellwithidentifier:id]; if(Cell = =Nil) {Cell=[[UITableViewCell alloc] Initwithstyle:uitableviewcellstylesubtitle Reuseidentifier:id]; //cell.accessorytype = uitableviewcellaccessorydisclosureindicator;Cell.accessorytype =Uitableviewcellaccessorydetailbutton; //set the background and selected graphs /*Cell.backgroundcolor = [Uicolor Redcolor]; UIImage *bgimg = [UIImage imagenamed:@ "img_01"]; Cell.backgroundview = [[Uiimageview alloc] initwithimage:bgimg]; UIImage *selectbgimg = [UIImage imagenamed:@ "img_02"]; Cell.selectedbackgroundview = [[Uiimageview alloc]initwithimage:selectbgimg];*/} Hero*hero =Self.heros[indexpath.row]; Cell.textLabel.text=Hero.name; Cell.imageView.image=[UIImage ImageNamed:hero.icon]; Cell.detailTextLabel.text=Hero.intro; /*Switch Uiswitch * swicher = [[Uiswitch alloc]init]; [Swicher addtarget:self Action: @selector (swtichchanged:) forcontrolevents:uicontroleventvaluechanged]; Cell.accessoryview = Swicher;*/ returncell;}//Switch- (void) swtichchanged: (Uiswitch *) sender{NSLog (@"%s%@", __func__,sender);}//Detail-(void) TableView: (UITableView *) TableView Didselectrowatindexpath: (Nsindexpath *) indexpath{//Button}-(void) TableView: (UITableView *) TableView Accessorybuttontappedforrowwithindexpath: (Nsindexpath *) indexpath{}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}@end
Ios-Hero League character show