IOS开发基础之英雄展示完整版
生活随笔
收集整理的這篇文章主要介紹了
IOS开发基础之英雄展示完整版
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
IOS開發(fā)基礎(chǔ)之英雄展示完整版
// // ViewController.m // 15-英雄展示-單組數(shù)據(jù) // // 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:@"確認(rèn)" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){//NSLog(@"點(diǎn)擊了確認(rèn)按鈕");NSLog(@"%@",action.title);// action.title}];UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action){NSLog(@"點(diǎn)擊了取消按鈕");}];[alert addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {// textField.placeholder=@"請(qǐng)?zhí)顚懩姆答佇畔?#34;;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];// 單元格重復(fù)使用//在創(chuàng)建單元格的時(shí)候指定一個(gè)重用ID// 當(dāng)需要一個(gè)新的單元格的時(shí)候,先去緩存池中找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-英雄展示-單組數(shù)據(jù) // // 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-英雄展示-單組數(shù)據(jù) // // 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總結(jié)
以上是生活随笔為你收集整理的IOS开发基础之英雄展示完整版的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于C编程的一点感受
- 下一篇: 阶乘的精确值 大数问题