IOS开发基础之英雄展示完整版

//
//  ViewController.m
//  15-英雄展示-单组数据
//
//  Created by 鲁军 on 2021/2/3.
//#import "ViewController.h"
#import "CZHero.h"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>@property(nonatomic,strong)NSArray *heros;@property (weak, nonatomic) IBOutlet UITableView *tableView;@end@implementation ViewController- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{//NSLog(@"%ld",(long) indexPath.row);CZHero *hero = self.heros[indexPath.row];UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"编辑英雄" message:nil preferredStyle:UIAlertControllerStyleAlert];UIAlertAction *conform = [UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){//NSLog(@"点击了确认按钮");NSLog(@"%@",action.title);//    action.title}];UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action){NSLog(@"点击了取消按钮");}];[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {// textField.placeholder=@"请填写您的反馈信息";textField.text=hero.name;}] ;[alert addAction:conform];[alert addAction:cancel];[self presentViewController:alert animated:YES completion:nil];
}//- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{//
//    int rowNum = indexPath.row;
//    if(rowNum%2==0){//
//        return 60;
//    }else{//        return 60;
//    }
//
//}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{CZHero *model =self.heros[indexPath.row];// UITableViewCell *cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:nil];// 单元格重复使用//在创建单元格的时候指定一个重用ID//  当需要一个新的单元格的时候,先去缓存池中找static NSString *ID = @"hero_cell";UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];if(cell==nil){cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID];}cell.imageView.image=[UIImage imageNamed:model.icon];cell.textLabel.text=model.name;cell.detailTextLabel.text=model.intro;cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;NSLog(@"%p----行索引 = %ld",cell,(long)indexPath.row);// cell.accessoryView =[[UISwitch alloc] init];
//    if(indexPath.row%2==0)
//    {//        cell.backgroundColor=[UIColor yellowColor];
//    }else{//
//        cell.backgroundColor=[UIColor blueColor];
//    }
//    UIView *bgView = [[UIView alloc] init];
//    bgView.backgroundColor = [UIColor greenColor];
//
//    cell.selectedBackgroundView =bgView;return cell;
}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{return self.heros.count;
}//
//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{//    return 1;
//}- (NSArray *)heros{if(_heros==nil){NSString *path = [[NSBundle mainBundle] pathForResource:@"heros.plist" ofType:nil];NSArray *arrayDict=[NSArray arrayWithContentsOfFile:path];NSMutableArray *arrayModels = [NSMutableArray array];for(NSDictionary *dict in arrayDict){CZHero *model = [CZHero heroWithDict:dict];[arrayModels addObject:model];}_heros = arrayModels;}return _heros;}- (void)viewDidLoad {[super viewDidLoad];// Do any additional setup after loading the view.// self.tableView.rowHeight=80;// self.tableView.separatorColor=[UIColor redColor];//self.tableView.separatorStyle=UITableViewCellSeparatorStyleNone;self.tableView.tableHeaderView=[UIButton buttonWithType:UIButtonTypeContactAdd];self.tableView.tableFooterView=[[UISwitch alloc] init];}@end
//
//  CZHero.h
//  15-英雄展示-单组数据
//
//  Created by 鲁军 on 2021/2/3.
//#import <Foundation/Foundation.h>NS_ASSUME_NONNULL_BEGIN@interface CZHero : NSObject@property(nonatomic,copy)NSString *icon;
@property(nonatomic,copy)NSString *intro;
@property(nonatomic,copy)NSString *name;-(instancetype)initWithDict:(NSDictionary *)dict;
+(instancetype)heroWithDict:(NSDictionary *)dict;@endNS_ASSUME_NONNULL_END
//
//  CZHero.m
//  15-英雄展示-单组数据
//
//  Created by 鲁军 on 2021/2/3.
//#import "CZHero.h"@implementation CZHero-(instancetype)initWithDict:(NSDictionary *)dict{if(self== [super init]){[self setValuesForKeysWithDictionary:dict];}return  self;
}
+(instancetype)heroWithDict:(NSDictionary *)dict{return [[self alloc] initWithDict:dict];
}@end

IOS开发基础之英雄展示完整版相关推荐

  1. IOS开发之UI基础LOL英雄展示-15

    IOS开发之UI基础LOL英雄展示-15 // // ViewController.m // 15-英雄展示-单组数据 // // Created by 鲁军 on 2021/2/3. //#impo ...

  2. iOS开发基础知识--碎片44

    iOS开发基础知识--碎片44  iOS开发基础知识--碎片44 1:App跳转至系统Settings 跳转在IOS8以上跟以下是有区别的,如果是IOS8以上可以如下设置: NSURL *url = ...

  3. IOS开发基础之网易新闻UICollectionView的使用第3天

    IOS开发基础之网易新闻UICollectionView的使用第3天 由于第3天的UICollectionView 并不实现,我查阅相关资料,也没解决,先从本地的plist加载的数据,不是网络的上的数 ...

  4. IOS开发基础之模拟科技头条项目案例32

    IOS开发基础之模拟科技头条项目案例32 说说这个项目的技术要点核心 ,首先是异步网络请求,block的回调,sdWebImage的使用.各个控件的使用,NSDate日期的转换.自动适配屏幕工作,模型 ...

  5. IOS开发基础之摇奖机案例

    IOS开发基础之摇奖机案例 // ViewController.m // 33-摇奖机器 // Created by 鲁军 on 2021/3/9. #import "ViewControl ...

  6. IOS开发基础之汽车品牌项目-14

    IOS开发基础之汽车品牌项目-14 // // ViewController.m // 16-汽车品牌展示02 // // Created by 鲁军 on 2021/2/3. //#import & ...

  7. iOS开发基础知识--碎片27

     iOS开发基础知识--碎片27 1:iOS中的round/ceil/floorf extern float ceilf(float); extern double ceil(double); ext ...

  8. iOS开发基础知识--碎片41

    iOS开发基础知识--碎片41 1:UIWebView加载本地的HTML NSString *path = [[NSBundle mainBundle] bundlePath]; NSURL *bas ...

  9. java web开发实战经典 源码_李兴华 java_web开发实战经典 源码 完整版收集共享

    李兴华 java_web开发实战经典 源码 完整版收集共享 01f8a7  在  2018-11-07 20:41:33  上传  10.92 MB 第1章 JAVA WEB开发简介 1.1.WEB发 ...

最新文章

  1. Linux下内存泄露工具
  2. java中map比较大小_java中对map根据value进行排序
  3. 使用vivado进行逻辑开发时,进行到Generate Bitstream时报错
  4. javaScript面试题大全
  5. 首页增加了“阅读排行”
  6. python+selenium小米商城红米K40手机抢购!
  7. 百度输入法皮肤工具提示 CSS,百度手机输入法皮肤布局制作工具
  8. 联想昭阳E46G笔记本识别4G内存问题
  9. python遍历列表中所有元素_python如何遍历列表所有元素?
  10. 铁甲小宝像车轮的是什么机器人_铁甲小宝里的机器人都叫什么名字啊
  11. 学3D建模需要有美术功底吗?
  12. 跨链桥:用零知识证明桥接多链宇宙
  13. java插入图片_如何在java窗体程序中添加图片
  14. 迅为i.MX6ULL终结者Mfgtools修改单独只烧写Uboot,内核,文件系统
  15. 关于编程语言和编程工具
  16. 适合中小企业的ERP管理软件如何选择?
  17. 项目一 认识Linux操作系统
  18. 鸿蒙音响怎么调,专业音响师必知的EQ调整小技巧
  19. LCD液晶屏工作原理
  20. 那些年,我们用过的服务器软件

热门文章

  1. ai边缘平滑_AI基础教程113:“效果”菜单之“画笔描边”(一)喷溅效果
  2. jquery去掉数组最后一个元素_从数组中删除最后一项
  3. 基于matlab 论文知网,基于MATLAB的校园图像处理与分析
  4. 华为重磅反击,鸿蒙来了!
  5. 机器人是如何群居生活的?
  6. HDLBits答案(4)_如何避免生成锁存器?
  7. Ultra96_v2实现交通标示识别
  8. 二元函数泰勒公式例题_高等数学入门——二元函数可微性的判断方法总结
  9. python办公自动化博客_自动化办公 Python 操控 Word
  10. 从第一范式到第二范式所做的操作是_给女同事讲解MySQL数据库范式与反范式,她直夸我“技术好”