您当前的位置: 首页 >  ar

white camel

暂无认证

  • 1浏览

    0关注

    442博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

UI 一一 自定义等高cell (storyboard方式)

white camel 发布时间:2017-08-14 17:21:14 ,浏览量:1

使用storyboard 和 xib的方式基本类似,

长话短说直接上代码.

ZYTg文件

@interface ZYTg : NSObject  
  
/** 图标 */  
@property (nonatomic, copy) NSString *icon;  
  
/** 标题 */  
@property (nonatomic, copy) NSString *title;  
  
/** 价格 */  
@property (nonatomic, copy) NSString *price;  
  
/** 购买数 */  
@property (nonatomic, copy) NSString *buyCount;  
  
@end  
  
@implementation ZYTg  
  
@end  
ZYTgCell文件

#import   
  
@class ZYTg;  
@interface ZYTgCell : UITableViewCell  
  
/** ZYTg模型 */  
@property(nonatomic,strong)ZYTg * tg;  
  
@end  
  
#import "ZYTg.h"  
  
@interface ZYTgCell ()  
  
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;  
  
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;  
  
@property (weak, nonatomic) IBOutlet UILabel *priceLabel;  
  
@property (weak, nonatomic) IBOutlet UILabel *buyCountLabel;  
  
@end  
  
@implementation ZYTgCell  
  
// 重写set方法,设置数据  
- (void)setTg:(ZYTg *)tg  
{  
    _tg = tg;  
    self.iconImageView.image = [UIImage imageNamed:tg.icon];  
    self.titleLabel.text = tg.title;  
    self.priceLabel.text = [NSString stringWithFormat:@"¥%@",tg.price];  
    self.buyCountLabel.text = [NSString stringWithFormat:@"%@人已购买",tg.buyCount];  
      
}  
  
@end 
Main.storyboard 文件

设置不同类型的cell,在storyboard中

ViewController 文件

#import "ViewController.h"
#import "MJExtension.h"
#import "ZYTgCell.h"
#import "ZYTg.h"

@interface ViewController ()

@property (nonatomic,strong) NSArray *tgs;

@end

@implementation ViewController

- (NSArray *)tgs
{
    if (_tgs == nil) {
        
        _tgs = [ZYTg mj_objectArrayWithFilename:@"tgs.plist"];
    }
    return _tgs;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.tableView.rowHeight = 70;
}

#pragma -mark 数据源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.tgs.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (indexPath.row % 2 == 0) {
        // 创建一个重用标识,去缓存池中取ID标识的cell
        static NSString *ID = @"tg";
        ZYTgCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
        
        // 设置每一行cell的数据
        cell.tg = self.tgs[indexPath.row];
        return cell;
    }else{
        
        return [tableView dequeueReusableCellWithIdentifier:@"test"];
    }
    
}


@end

关注
打赏
1661428283
查看更多评论
立即登录/注册

微信扫码登录

0.0390s