iOS 购物—个人中心界面
上一个QQ界面真实无心插柳,想不到一个新手的普通界面可以上首页推荐,在这谢谢那些csdn工作者对新手的支持,谢谢soledadzz 的特别推荐;
以下这个界面也是师傅锻炼我的题目主要是让我熟悉table的使用;我想尽量的去用mvc,尽量的去实现界面与数据的分离,可是一个水平没有达到,不知道这种界面算不算一个真正的分离,还差多少,假设您看出了问题,请留一下言,帮忙扶一把,谢谢!
文件原代码究竟部的链接下载,谢谢,须要一分来赚点外块,假设没有积分能够留言,或者留下QQ我发给大家。
因为本人ps技术的原因,没可以将底部的四张小图片弄出来,致使底部的tabBar 没有图片,大家可以自己加上。
先来说下文件:
由于近期看可代码规范的一些东西,刚開始用,我想名字什么的尽量的去做到,看到名字就知道是干嘛的。
在personalcentreTable文件里放得是 界面中间的table和cell 以下personalcentreHeadview 是界面头部也就是 头像,蓝色背景那部分
personalcentreview 就是整个的界面部分了;
其它地方没有必要介绍了;
先在Appdelegate中实现了tabBar
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.
_window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
UIViewController *vc1 = [[UIViewController alloc]init];
vc1.view.backgroundColor = [UIColor redColor];
vc1.title = @"首页";
UIViewController *vc2 = [[UIViewController alloc]init];
vc2.view.backgroundColor = [UIColor grayColor];
vc2.title = @"商家";
UIViewController *vc3 = [[UIViewController alloc]init];
vc3.view.backgroundColor = [UIColor greenColor];
vc3.title = @"购物车";
ViewController *vc4 = [[ViewController alloc]init];
vc4.title = @"个人中心";
NSArray *arrayVC = @[vc1,vc2,vc3,vc4];
self.tabBarC = [[UITabBarController alloc]init];
self.tabBarC.viewControllers = arrayVC;
_window.rootViewController = self.tabBarC;
[_window makeKeyAndVisible];
return YES;
}
构造数据:
NSDictionary *dictionary = @{@"personal_protrait":@"icon.png",
@"personal_name":@"雪松",
@"personal_integral":@"200",
@"personal_welfare":@"59",
@"personal_table":@{@"待付款订单":@"10",
@"待发货订单":@"5",
@"已发货订单":@"4"}
};
先来看下cell吧
@property (nonatomic,strong) UILabel *nameLabel;
@property (nonatomic,strong) UILabel *numberLabel;
@property (nonatomic,strong) UIImageView *rightImageView;
一个名字 ,一个数字,一个图标 能够对比图一看就明确;
- (id)initWithName:(NSString *)name number:(NSString *)number rightImage:(UIImage *)image
{
self = [super init];
if (self) {
//设置文字
_nameLabel = [[UILabel alloc]initWithFrame:CGRectMake(20, 10, 100, 20)];
_nameLabel.text =name;
[self addSubview:_nameLabel]; //设置标识数字
_numberLabel = [[UILabel alloc]initWithFrame:CGRectMake(250, 10, 30, 20)];
_numberLabel.text = number;
_numberLabel.textAlignment = 1;
_numberLabel.textColor = [UIColor redColor];
[self addSubview:_numberLabel]; //设置右边图片
_rightImageView = [[UIImageView alloc]initWithFrame:CGRectMake(290, 10, 15, 20)];
_rightImageView.image = image;
[self addSubview:_rightImageView]; }
return self;
}
接下来是table了
@interface PersonalCentreTable : UITableView<UITableViewDataSource,UITableViewDelegate> @property (nonatomic,copy) NSDictionary *dataDictionary; //传递的数据 - (id)initWithDictionary:(NSDictionary *)dictionary;
@end
在实现table时我想 有4个section 并且行数也不一样,每行的内容也不一样,这样在
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath
*)indexPath
怎么写啊,要一个一个if的去推断是哪个section 然后推断是哪一行吗?这样费劲了,于是我想到了数组。一个老手应该自然会想到,可是作为新手能用还是蛮高兴的;
tableArray = @[@[@"待付款订单",
@"待发货订单",
@"已发货订单"],
@[@"已完毕订单"],
@[@"售后服务"],
@[@"设置"]];
这个数组然后与以下的代码结合起来就简洁多了
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
PersonalCentreTableCell *cell ; if (indexPath.section == 0) {
NSString *name = [(NSArray *)[tableArray objectAtIndex:indexPath.section]
objectAtIndex:indexPath.row];
cell = [[PersonalCentreTableCell alloc]
initWithName:name
number:[_dataDictionary objectForKey:name]
rightImage:[UIImage imageNamed:@"rightImage.png"]];
}
else {
cell = [[PersonalCentreTableCell alloc]
initWithName:[(NSArray *)[tableArray objectAtIndex:indexPath.section]
objectAtIndex:indexPath.row]
number:@""
rightImage:[UIImage imageNamed:@"rightImage.png"]];
}
return cell;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return section == 0? 3:1;
//return ((NSArray *)[_dataArray objectAtIndex:section]).count;
}
这里我想说的是我们应该多去用 ?: 少去写if,应该先考虑?: 这样我们的代码更加整洁;
说完这些小部分,那让我们来看看整个部分吧personalcentreview;
<span style="font-size:12px;">@interface PersonalCentreView : UIView @property (nonatomic,strong) UILabel *titleLabel;//标题
@property (nonatomic,strong) PersonalCentreHeadView *personalCentreHeadView;//头部 个人头像部分
@property (nonatomic,strong) PersonalCentreTable *personalCentreTable;//表格部分
@property (nonatomic,copy) NSDictionary *dataDictionary;//数据 - (id)initWithDictionary:(NSDictionary *)dictionary;
@end</span>
- (id)initWithDictionary:(NSDictionary *)dictionary
{
self = [super init];
if (self) {
_dataDictionary = dictionary; //self.frame = CGRectMake(0, 0, 320, 480); self.backgroundColor = [UIColor colorWithRed:238/255.0 green:238/255.0 blue:238/255.0 alpha:1]; // 设置标题
_titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 30, 280, 20)];
_titleLabel.text = @"个人中心";
_titleLabel.textAlignment = 1;//居中
// _titleLabel.textColor = [UIColor whiteColor];
[self addSubview:_titleLabel]; //设置头像部分
_personalCentreHeadView = [[PersonalCentreHeadView alloc]initWithPortrait:[dictionary objectForKey:@"personal_image"]
Name:[dictionary objectForKey:@"personal_name"]
Integral:[dictionary objectForKey: @"personal_integral"]
Welfare:[dictionary objectForKey:@"personal_welfare"]];
[self addSubview:_personalCentreHeadView]; //设置表格
_personalCentreTable = [[PersonalCentreTable alloc]initWithDictionary:[dictionary objectForKey:@"personal_table"]];
[self addSubview:_personalCentreTable]; }
return self;
}
源代码下载地址:http://download.csdn.net/detail/u010123208/7805865
再次说一下,这些东西是给我们新手看的,也许可以帮到你们,由于我在学习的时候也想有个完整的样例来练一练手。
大神们,建议意见,我们希望你们能留下。“一个简单的界面,也好意思说。。。”这种话我们不希望看到,我就不相信,一年两年之后你还会比我们强。
iOS 购物—个人中心界面的更多相关文章
- IOS Notification 通知中心
1. 通知中心概述 通知中心实际上是在程序内部提供了消息广播的一种机制.通知中心不能在进程间进行通信.实际上就是一个二传手,把接收到的消息,根据内部的一个消息转发表,来将消息转发给需要的对象. ...
- Xamarin iOS教程之编辑界面编写代码
Xamarin iOS教程之编辑界面编写代码 Xamarin iOS的Interface Builder Interface Builder被称为编辑界面.它是一个虚拟的图形化设计工具,用来为iOS应 ...
- iOS Swift WisdomHUD 提示界面框架
iOS Swift WisdomHUD 提示界面框架 Framework Use profile(应用简介) 一:WisdomHUD简介 今天给大家介绍一款iOS的界面显示器:WisdomHUD,W ...
- IOS中通知中心(NSNotificationCenter)
摘要 NSNotification是IOS中一个调度消息通知的类,采用单例模式设计,在程序中实现传值.回调等地方应用很广. IOS中通知中心NSNotificationCenter应用总结 一.了 ...
- 安卓端调用h5界面js方法和ios端调用h5界面js方法
备注:本人为h5开发人员,不懂安卓和ios,这是开发小伙伴对接联调的主代码. 1.iOS端调用h5界面js方法: 2.安卓端调用h5界面js方法: @Override protect ...
- iOS 跳转系统设置界面
iOS 跳转系统设置界面 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Pri ...
- iOS 8 Auto Layout界面自动布局系列5-自身内容尺寸约束、修改约束、布局动画
首先感谢众多网友的支持,最近我实在是事情太多,所以没有写太多.不过看到大家的反馈和评价,我还是要坚持挤出时间给大家分享我的经验.如果你对我写的东西有任何建议.意见或者疑问,请到我的CSDN博客留言: ...
- IOS与Android APP界面设计规范要点
IOS篇 一.尺寸及分辨率 iPhone界面尺寸:320*480.640*960.640*1136 iPhone6:4.7英寸(1334×750),iPhone6 Plus:5.5英寸(1920×10 ...
- iOS 8 Auto Layout界面自动布局系列2-使用Xcode的Interface Builder添加布局约束
http://blog.csdn.net/pucker/article/details/41843511 上一篇文章<iOS 8界面自动布局系列-1>简要介绍了iOS界面布局方式的前世今生 ...
随机推荐
- Python基础 2----Python 基础语法
1 模块导入原理 1 模块是包含函数,类,变量的独立的Python文件 2 导入系统的模块 比如我在家目录下创建一个m.py的文件,我们导入了许多的系统模块,比如time,string等等.这边就类似 ...
- COCOS2D-X之帧动画的一种实现Demo
这个Demo主要是实现帧动画,建议游戏中少用帧动画.废话少说直接上代码. 一.我们直接在COCOS2D-X自带的HelloCpp的工程中添加代码即可.我们在初始化中添加如下代码并附上图片资源. CCS ...
- 线段树菜鸟一题+归并排序【求逆序数】POJ2299
题目链接:http://poj.org/problem?id=2299 归并排序解法链接:http://blog.csdn.net/lyy289065406/article/details/66473 ...
- 591 - Box of Bricks
Box of Bricks Little Bob likes playing with his box of bricks. He puts the bricks one upon another ...
- STL 二分查找三兄弟(lower_bound(),upper_bound(),binary_search())
一:起因 (1)STL中关于二分查找的函数有三个:lower_bound .upper_bound .binary_search -- 这三个函数都运用于有序区间(当然这也是运用二分查找的前提),以 ...
- li里的a标签浮动了,为什么li本身也浮动了?
<ul> <li><a href="#"></a></li> <li><a href="#& ...
- WSDL中文版——详解
为什么使用WSDL? 像Internet协议之类的标准有没有为权威所利用,或者人们这样看待它是因为顺之所获的好处远远超出了代价?曾经有许多试图建立的标准都流产了.有时候,那些还没有普遍使用的标准甚至由 ...
- codeforces 604A Uncowed Forces
题目链接:http://codeforces.com/problemset/problem/604/A 题意:求cf比赛每次能够增加的排名,运算规则会告诉你 题目分类:数学 题目分析:用题目给的公式直 ...
- [Android学习笔记]双缓冲绘图技术
双缓冲技术绘图: 什么情况下产生的双缓冲技术?当数据量很大时,绘图可能需要花费很长的时间,这样屏幕就会出现卡顿,闪烁等现象. 什么是双缓冲技术?双缓冲是在内存中创建一个与屏幕绘制区域一致的对象,先将图 ...
- 用jsp写注冊页面
包含单选框.多选框.session的应用,页面自己主动跳转,中文乱码的处理,入门级 对于中文乱码的处理,注意几点:注冊页面数据提交方式为post不能忘了写,页面编码方式为gbk,处理提交信息的doRe ...