国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

[iOS基礎控件-6.2]LOL英雄列表UITableView單項顯示

2019-11-14 19:48:50
字體:
來源:轉載
供稿:網友
A.需求
1.使用只有一個section的TableView來顯示LOL 的英雄列表
2.內容包括標題、副標題、圖標
3.使用plain樣式
4.使用MVC模式
 
Image(74)
 
heros.plist 文件結構:
Image(75)
 
 
這個其實很簡單,直接上代碼了
 1 // 2 //  Hero.h 3 //  LOLHero 4 // 5 //  Created by hellovoidworld on 14/12/1. 6 //  Copyright (c) 2014年 hellovoidworld. All rights reserved. 7 // 8  9 #import <Foundation/Foundation.h>10 11 @interface Hero : NSObject12 13 @PRoperty(nonatomic, copy) NSString *icon;14 @property(nonatomic, copy) NSString *intro;15 @property(nonatomic, copy) NSString *name;16 17 - (instancetype) initWithDictionary:(NSDictionary *) dictionary;18 + (instancetype) heroWithDictionary:(NSDictionary *) dictionary;19 + (instancetype) hero;20 21 @end
 
 1 // 2 //  Hero.m 3 //  LOLHero 4 // 5 //  Created by hellovoidworld on 14/12/1. 6 //  Copyright (c) 2014年 hellovoidworld. All rights reserved. 7 // 8  9 #import "Hero.h"10 11 @implementation Hero12 13 - (instancetype) initWithDictionary:(NSDictionary *) dictionary {14     if (self = [super init]) {15         self.icon = dictionary[@"icon"];16         self.intro = dictionary[@"intro"];17         self.name = dictionary[@"name"];18     }19    20     return self;21 }22 23 + (instancetype) heroWithDictionary:(NSDictionary *) dictionary {24     return [[self alloc] initWithDictionary:dictionary];25 }26 27 + (instancetype) hero {28     return [self heroWithDictionary:nil];29 }30 31 @end
 
 1 // 2 //  ViewController.m 3 //  LOLHero 4 // 5 //  Created by hellovoidworld on 14/12/1. 6 //  Copyright (c) 2014年 hellovoidworld. All rights reserved. 7 // 8  9 #import "ViewController.h"10 #import "Hero.h"11 12 @interface ViewController () <UITableViewDataSource>13 14 // UITableView15 @property (weak, nonatomic) IBOutlet UITableView *tableView;16 17 // 所有hero資料18 @property(nonatomic, strong) NSArray *heros;19 20 @end21 22 @implementation ViewController23 24 - (void)viewDidLoad {25     [super viewDidLoad];26     // Do any additional setup after loading the view, typically from a nib.27    28     // 設置dataSource29     self.tableView.dataSource = self;30    31     // 設置行高32     self.tableView.rowHeight = 60;33 }34 35 - (void)didReceiveMemoryWarning {36     [super didReceiveMemoryWarning];37     // Dispose of any resources that can be recreated.38 }39 40 /** 隱藏狀態欄 */41 - (BOOL)prefersstatusBarHidden {42     return YES;43 }44 45 /** 延遲加載hero數據 */46 - (NSArray *) heros {47     if (nil == _heros) {48         NSArray *dictArray = [NSArray arrayWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"heros.plist" ofType:nil]];49        50         NSMutableArray *herosArray = [NSMutableArray array];51         for (NSDictionary *dict in dictArray) {52             Hero *hero = [Hero heroWithDictionary:dict];53             [herosArray addObject:hero];54         }55        56         _heros = herosArray;57     }58    59     return _heros;60 }61 62 #pragma mark - 列表方法63 64 // section數, 默認是165 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {66     return 1;67 }68 69 // 特定section的行數70 - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {71     return self.heros.count;72 }73 74 75 // 特定行的內容76 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {77     Hero *hero = self.heros[indexPath.row];78    79     // 必須使用"UITableViewCellStyleSubtitle"才能顯示副標題80     UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];81 82     // 標題83     cell.textLabel.text = hero.name;84    85     // 副標題86     cell.detailTextLabel.text = hero.intro;87    88     // 圖標89     cell.imageView.image = [UIImage imageNamed:hero.icon];90    91     return cell;92 }93 94 @end

 


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 南汇区| 丰县| 奉新县| 泸溪县| 丹东市| 阳泉市| 浙江省| 东丰县| 临桂县| 武陟县| 台东市| 宜都市| 玛纳斯县| 湖北省| 巴南区| 灵宝市| 钦州市| 武清区| 华坪县| 白水县| 德阳市| 武清区| 天门市| 阿克陶县| 隆回县| 斗六市| 会泽县| 苏尼特右旗| 元氏县| 延津县| 定安县| 织金县| 台北市| 繁峙县| 巴东县| 金华市| 西藏| 罗源县| 桑日县| 前郭尔| 鄱阳县|