您的位置:首页 > 移动开发 > IOS开发

iOS开发总结之自定义等高cell-storyboard

2016-04-14 00:28 453 查看

1.storybord中添加子控件并设置tag



2.代码:

#import "XMGDealsViewController.h"
#import "XMGDeal.h"

@interface XMGDealsViewController ()
/** 所有的团购数据 */
@property (nonatomic, strong) NSArray *deals;
@end

@implementation XMGDealsViewController

- (NSArray *)deals
{
if (_deals == nil) {
// 加载plist中的字典数组
NSString *path = [[NSBundle mainBundle] pathForResource:@"deals.plist" ofType:nil];
NSArray *dictArray = [NSArray arrayWithContentsOfFile:path];

// 字典数组 -> 模型数组
NSMutableArray *dealArray = [NSMutableArray array];
for (NSDictionary *dict in dictArray) {
XMGDeal *deal = [XMGDeal dealWithDict:dict];
[dealArray addObject:deal];
}

_deals = dealArray;
}
return _deals;
}

- (void)viewDidLoad {
[super viewDidLoad];

}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.deals.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *ID = @"deal";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];

// 取出模型数据
XMGDeal *deal = self.deals[indexPath.row];

// 设置数据
UIImageView *iconView = (UIImageView *)[cell viewWithTag:10];
iconView.image = [UIImage imageNamed:deal.icon];

UILabel *titleLabel = (UILabel *)[cell viewWithTag:20];
titleLabel.text = deal.title;

UILabel *priceLabel = (UILabel *)[cell viewWithTag:30];
priceLabel.text = [NSString stringWithFormat:@"¥%@", deal.price];

UILabel *buyCountLabel = (UILabel *)[cell viewWithTag:40];
buyCountLabel.text = [NSString stringWithFormat:@"%@人已购买", deal.buyCount];

return cell;
}

@end


3.效果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: