IOS开发之UI基础LOL英雄展示-15
生活随笔
收集整理的這篇文章主要介紹了
IOS开发之UI基础LOL英雄展示-15
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
IOS開發(fā)之UI基礎(chǔ)LOL英雄展示-15
// // 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:@"這是一些信息" preferredStyle:UIAlertControllerStyleAlert];}//- (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];// 單元格重復使用//在創(chuàng)建單元格的時候指定一個重用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-英雄展示-單組數(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开发之UI基础LOL英雄展示-15的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 不怕烧钱怕翻车:雷军与马化腾现场“过招”
- 下一篇: 关于C编程的一点感受