日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

iOS-英雄联盟人物展示

發(fā)布時(shí)間:2024/6/21 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 iOS-英雄联盟人物展示 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

素材:圖片庫(kù)和一個(gè)英雄資料的plist

文件:一個(gè)英雄數(shù)據(jù)封裝的模塊

// // Hero.h // 多組表格 // // Created by YaguangZhu on 15/8/13. // Copyright (c) 2015年 YaguangZhu. All rights reserved. // #import <Foundation/Foundation.h>@interface Hero : 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 // 多組表格 // // Created by YaguangZhu on 15/8/13. // Copyright (c) 2015年 YaguangZhu. All rights reserved. // #import "Hero.h"@implementation Hero - (instancetype)initWithDict:(NSDictionary *)dict {self = [super init];if (self) {[self setValuesForKeysWithDictionary:dict];}return self; }+ (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 *dict in array) {[arrayM addObject:[self heroWithDict:dict]];}return arrayM; } @end

主文件:

// // ViewController.m // 多組表格 // // Created by YaguangZhu on 15/8/13. // Copyright (c) 2015年 YaguangZhu. All rights reserved. // #import "ViewController.h" #import "Hero.h"@interface ViewController ()<UITableViewDataSource,UITableViewDelegate> @property(nonatomic,strong)UITableView *tableView; @property (nonatomic,strong)NSArray *heros; @end@implementation ViewController- (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 = 80;self.tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;UIView *head = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];head.backgroundColor = [UIColor redColor];self.tableView.tableHeaderView = head;UIView *foot = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];foot.backgroundColor = [UIColor redColor];//foot 做刷新 head 做廣告self.tableView.tableFooterView =foot;// Do any additional setup after loading the view, typically from a nib. }- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {return self.heros.count; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {//為了加入緩存池,換個(gè)代碼 下面這句重寫//UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil]; //static 靜態(tài)變量 能夠保證系統(tǒng)為變量在內(nèi)存中只分配一次內(nèi)存空間,但不能創(chuàng)建太多,因?yàn)椴粫?huì)被釋放,只有程序銷毀時(shí),才會(huì)釋放static NSString *ID = @"cell";UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];if (cell == nil) {cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];//cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;cell.accessoryType =UITableViewCellAccessoryDetailButton;// 設(shè)置背景圖和選中 的圖/* 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;/* 開(kāi)關(guān)UISwitch * swicher = [[UISwitch alloc]init];[swicher addTarget:self action:@selector(swtichChanged :) forControlEvents:UIControlEventValueChanged];cell.accessoryView = swicher;*/return cell; } //開(kāi)關(guān) - (void)swtichChanged:(UISwitch *)sender {NSLog(@"%s %@",__func__,sender); } // 詳細(xì) -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {//按鈕 }-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath {} - (void)didReceiveMemoryWarning {[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated. }@end

?

轉(zhuǎn)載于:https://www.cnblogs.com/zhuyaguang/p/4733993.html

總結(jié)

以上是生活随笔為你收集整理的iOS-英雄联盟人物展示的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。