Oc plist文件重写单元格
2017-11-15 10:17
239 查看
首先创建Plist文件.
单元格MyTableViewCell.h
单元格MyTableViewCell.m
ViewController.m
单元格MyTableViewCell.h
#import <UIKit/UIKit.h> @interface MyTableViewCell : UITableViewCell @property(nonatomic,strong)UIImageView *theImage ; @property(nonatomic,strong)UILabel *theL1,*theL2,*theL3,*theL4,*theL5 ; @end
单元格MyTableViewCell.m
#import "MyTableViewCell.h" @implementation MyTableViewCell //懒加载模式 使用下划线 -(UIImageView *)theImage { if (!_theImage) { _theImage = [[UIImageView alloc]initWithFrame:CGRectMake(5, 5, 80, 80)]; [_theImage.layer setCornerRadius:80/2]; _theImage.layer.masksToBounds = YES ; //添加到视图 [self addSubview:self.theImage]; } return _theImage ; } //UILab懒加载 -(UILabel*)theL1 { if (!_theL1) { _theL1 = [[UILabel alloc]initWithFrame:CGRectMake(85, 5, 160, 30)]; //添加到视图 [self addSubview:self.theL1]; } return _theL1 ; } -(UILabel*)theL2 { if (!_theL2) { _theL2 = [[UILabel alloc]initWithFrame:CGRectMake(85, 25, 160, 30)]; //添加到视图 [self addSubview:self.theL2]; } return _theL2 ; } -(UILabel*)theL3 { if (!_theL3) { _theL3 = [[UILabel alloc]initWithFrame:CGRectMake(85,45, 160, 30)]; //添加到视图 [self addSubview:self.theL3]; } return _theL3 ; } -(UILabel*)theL4 { if (!_theL4) { _theL4 = [[UI 4000 Label alloc]initWithFrame:CGRectMake(255, 5, 160, 30)]; //添加到视图 [self addSubview:self.theL4]; } return _theL4 ; } -(UILabel*)theL5 { if (!_theL5) { _theL5 = [[UILabel alloc]initWithFrame:CGRectMake(305, 45, 160, 30)]; //添加到视图 [self addSubview:self.theL5]; } return _theL5 ; } @end
ViewController.m
#import "ViewController.h" #import "MyTableViewCell.h" @interface ViewController ()<UITableViewDelegate,UITableViewDataSource> { NSDictionary *theDic; } @property(nonatomic,strong)UITableView *theTable ; @end @implementation ViewController -(UITableView *)theTable { if (!_theTable) { _theTable = [[UITableView alloc]initWithFrame:CGRectMake(0, 20, self.view.frame.size.width, self.view.frame.size.height-20) style:UITableViewStylePlain]; _theTable.delegate = self ; _theTable.dataSource = self ; _theTable.rowHeight = 80 ; } return _theTable; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [self.view addSubview:self.theTable]; NSString *path = [[NSBundle mainBundle]pathForResource:@"My list" ofType:@"plist"]; theDic = [NSDictionary dictionaryWithContentsOfFile:path]; } #pragma - #pragma mark -UITableViewDataSource - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return theDic.allKeys.count; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { MyTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"celled"]; if (!cell) { cell = [[MyTableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"celled"]; } NSString *key = [theDic.allKeys objectAtIndex:indexPath.row]; NSArray *arr = [theDic objectForKey:key]; cell.theImage.image = [UIImage imageNamed:arr[0]]; cell.theL1.text = key ; cell.theL2.text = arr[1]; cell.theL3.text = arr[2]; cell.theL4.text = arr[3]; cell.theL5.text = arr[4]; return cell ; } @end
相关文章推荐
- OC从plist文件中获取数据
- OC读取plist文件
- OC读取plist文件
- iOS之OC随笔-plist文件解析
- OC笔记 - 懒加载、plist文件加载、UIImageView帧动画(2015.2.4)
- 3、Info.plist文件介绍-OC+UI
- OC 创建和写入plist文件
- OC基础学习——如何解析plist文件和数据的归档和解档与json数据的解析
- IOS开发-OC学习-Info.plist文件解析
- 20150623_OC之属性列表文件plist
- OC-plist文件写入与读取
- plist文件+UITableViewController 实现静态单元格
- 将Texture Packer制作的.pvr.ccz和.plist文件还原为多个原图
- 向PLIST文件中追加数据
- cocos2d-x使用TexturePacker打包图片及使用生成的plist文件创建精灵动画
- 程序中的文件之沙盒以及plist文件的初步使用
- 在oc项目中添加swift文件,并设置oc-swift混编
- QT重写filedialog文件对话框
- 以plist文件做本地存储
- Info.plist与Prefix.pch修改文件位置遇到的问题及解决方法