图文混排解析Plist文件

创建一个继承UITableViewCell重写的类


//  MyCell.h
@property (nonatomic,strong)UIImageView *theHeadImg;

@property (nonatomic,strong)UIImageView *thePicture;

@property (nonatomic,strong)UILabel *theContent;

@property (nonatomic,strong)UILabel *theNickName;

@property (nonatomic,assign)NSInteger height,width;


////  MyCell.m

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier

{

if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])

{

[self addSubview:self.theHeadImg];

[self addSubview:self.theNickName];

[self addSubview:self.thePicture];

[self addSubview:self.theContent];

}

return self;

}

- (UIImageView *)theHeadImg

{

if (!_theHeadImg)

{

_theHeadImg  =  [[UIImageView alloc]initWithFrame:CGRectMake(20, 10, 44, 44)];

_theHeadImg.layer.cornerRadius = 22;

_theHeadImg.layer.masksToBounds = YES;

}

return _theHeadImg;

}

- (UILabel *)theNickName

{

if (!_theNickName)

{

_theNickName = [[UILabel alloc]initWithFrame:CGRectMake(74, 10, 150 , 44)];

}

return _theNickName;

}

- (UIImageView *)thePicture

{

if (!_thePicture)

{

_thePicture = [[UIImageView alloc]initWithFrame:CGRectMake(50, 130, 250, 150)];

}

return _thePicture;

}

- (UILabel *)theContent

{

if (!_theContent)

{

_theContent = [[UILabel alloc]initWithFrame:CGRectMake(20, 70, self.frame.size.width, 44)];

_theContent.numberOfLines = 0;

}

return _theContent;

}


//Model 继承 NSObject没有东西


//  ViewController.m

#import "MyCell.h"

#import "TheModel.h"

//协议

{

//全局变量

UITableView *_theTableView;

NSArray *_mutableArr;

NSArray *_plistArr;

CGFloat kHEIGHT;

NSString *path;

}

//====================================

kHEIGHT = 200;

//获取路径

path = [[NSBundle mainBundle] pathForResource:@"friends" ofType:@"plist"];

//初始化

_mutableArr = [NSArray arrayWithContentsOfFile:path];

//初始化

_theTableView = [[UITableView alloc]initWithFrame:self.view.frame];

//代理

_theTableView.delegate = self;

_theTableView.dataSource = self;

_theTableView.contentInset = UIEdgeInsetsMake(kHEIGHT, 0, 0, 0);

//添加到试图

[self.view addSubview:_theTableView];

//初始化view

UIImageView *headView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"headerImage1.jpg"]];

headView.frame = CGRectMake(0,-kHEIGHT, [UIScreen mainScreen].bounds.size.width, kHEIGHT);

headView.contentMode = UIViewContentModeScaleToFill;

//设置tag值

headView.tag = 101;

[_theTableView addSubview:headView];

//=======================================

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

return _mutableArr.count;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

MyCell  *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];

if (!cell)

{

cell = [[MyCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];

}

cell.theHeadImg.image = [UIImage imageNamed:[_mutableArr[indexPath.row] objectForKey:@"headImg"]];

cell.theNickName.text = [_mutableArr[indexPath.row] objectForKey:@"nickname"];

cell.theContent.text = [_mutableArr[indexPath.row] objectForKey:@"content"];

cell.thePicture.image = [UIImage imageNamed:[_mutableArr[indexPath.row] objectForKey:@"picture"]];

return cell;

}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

{

if (indexPath.row == 0)

{

return 150;

}

else

{

return 300;

}

}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView

{

CGPoint point = scrollView.contentOffset; if (point.y < -kHEIGHT) { CGRect rect = [_theTableView viewWithTag:101].frame; rect.origin.y = point.y; rect.size.height = -point.y; [_theTableView viewWithTag:101].frame = rect; }

}

接下来就是详细的plist文件


图文混排解析Plist文件_第1张图片
图文混排解析Plist文件_第2张图片

你可能感兴趣的:(图文混排解析Plist文件)