您的位置:首页 > 产品设计 > UI/UE

iOS开发UI篇—使用xib自定义UItableviewcell实现一个简单的团购应用界面布局

2014-11-12 15:56 363 查看
iOS开发UI篇—使用xib自定义UItableviewcell实现一个简单的团购应用界面布局

一、项目文件结构和plist文件

[b]

//
//  YYViewController.m
//  02-团购(使用xib和类完成数据展示)
//
//  Created by apple on 14-5-29.
//  Copyright (c) 2014年 itcase. All rights reserved.
//

#import "YYViewController.h"
#import "YYtgModel.h"
#import "YYtgcell.h"

@interface YYViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (strong, nonatomic) IBOutlet UITableView *tableview;

@property(strong,nonatomic)NSArray *tg;
@end

@implementation YYViewController

- (void)viewDidLoad
{
[super viewDidLoad];
self.tableview.rowHeight=80.f;
}
#pragma mark-  懒加载
-(NSArray *)tg
{
if (_tg==nil) {
NSString *fullpath=[[NSBundle mainBundle]pathForResource:@"tgs.plist" ofType:nil];
NSArray *temparray=[NSArray arrayWithContentsOfFile:fullpath];

NSMutableArray *arrayM=[NSMutableArray arrayWithCapacity:temparray.count];
for (NSDictionary *dict in temparray) {
YYtgModel *tg=[YYtgModel tgWithDict:dict];
[arrayM addObject:tg];
}
_tg=[arrayM mutableCopy];
}
return _tg;
}

#pragma mark- xib创建cell数据处理

#pragma mark 多少组
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

#pragma mark多少行
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return self.tg.count;
}

#pragma mark设置每组每行
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//1.创建cell
YYtgcell *cell=[YYtgcell tgcellWithTableView:tableView];

//2.获取当前行的模型,设置cell的数据
YYtgModel *tg=self.tg[indexPath.row];
cell.yytg=tg;

//3.返回cell
return cell;
}

#pragma mark- 隐藏状态栏
-(BOOL)prefersStatusBarHidden
{
return YES;
}

@end


View Code
四、推荐调整的项目文件结构



这是调整后的文件结构,完整的MVC架构。

注意:注意文件的命名规范。

提示技巧:批量改名,操作如下:



修改为想要的名称:

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