实战项目:通讯录 UI—第十一天
2.通过模态的形式推出视图,不需要依赖于导航控制器,通过使用present到下一个界面,通过dismiss返回到上一个界面
如何选择使用哪种视图的推出方法?
秘诀:看视图之间的依赖关系
1.当下一个页面要展示的数据依赖于上一个界面使用push

"ContactListTableViewController.h"
#import
"AddContactViewController.h"
#import
"DetailContactController.h"
#import
"CustomCell.h"
"Contacter.h"
(void)viewDidLoad
{
[super
viewDidLoad];
[self
configureNavigatinControllerBarContent];
}
//配置导航条的内容
- (void)configureNavigatinControllerBarContent{
//设置title
self.navigationItem.title
=
@"通讯录";
//设置左边添加联系人按钮
UIBarButtonItem
*leftItem =
[[UIBarButtonItem
alloc]initWithImage:[UIImage
imageNamed:@"add_contact"]style:(UIBarButtonItemStylePlain)
target:self
action:@selector(handleAdd:
)];
self.navigationItem.leftBarButtonItem
=
leftItem;
//配置导航条的背景颜色
self.navigationController.navigationBar.barTintColor
=
[UIColor
orangeColor];
//配置导航条内容的颜色
self.navigationController.navigationBar.tintColor
=
[UIColor
whiteColor];
//修改title的字体颜色
NSDictionary
*dic =
@{NSForegroundColorAttributeName
:
[UIColor
whiteColor]};
self.navigationController.navigationBar.titleTextAttributes
=
dic;
//右侧导航条为编辑按钮
self.navigationItem.rightBarButtonItem
=
self.editButtonItem;
#pragma mark
添加联系人按钮的方法
-
(void)handleAdd:
(UIBarButtonItem
*)leftItem{
NSLog(@"添加联系人");
//当前一个界面要展示的数据,依赖于后一个界面时,此时使用模态的形式推出视图,模态:是一种新的视图推出方式
//先创建要推出的试图控制器对象
AddContactViewController
*addVC
=[[AddContactViewController
alloc]init];
//给模态出来的视图控制添加导航控制器
UINavigationController
*navogationVC
= [[UINavigationController
alloc]initWithRootViewController:addVC];
//配置模态出现的样式
navogationVC.modalTransitionStyle
=
UIModalTransitionStyleFlipHorizontal;
//UIModalTransitionStyleCoverVertical
= 0,
//UIModalTransitionStyleFlipHorizontal,
//UIModalTransitionStyleCrossDissolve,
//UIModalTransitionStylePartialCurl
//模态不依赖于导航控制器,所以不需要拿到导航控制器
[self
presentViewController:navogationVC
animated:YES
completion:^{
//推出视图之后要做的一些操作,可以写在这里
}];
[addVC release];
}
- (void)didReceiveMemoryWarning
{
[super
didReceiveMemoryWarning];
//
Dispose of any resources that can be recreated.
}
#pragma mark - Table view data
source
(NSInteger)numberOfSectionsInTableView:(UITableView
*)tableView
{
return
10;
}
(NSInteger)tableView:(UITableView
*)tableView
numberOfRowsInSection:(NSInteger)section
{
return
10;
(UITableViewCell
*)tableView:(UITableView
*)tableView
cellForRowAtIndexPath:(NSIndexPath
*)indexPath
{
NSString
*idntifer
= @"cell";
CustomCell
*cell =
[tableView dequeueReusableCellWithIdentifier:idntifer];
if
(cell
== nil)
{
cell = [[CustomCell
alloc]initWithStyle:(UITableViewCellStyleValue1)
reuseIdentifier:idntifer];
}
//准备一个字典,使用给Model对象赋值
NSDictionary
*dic =
@{@"name":@"小韩哥",@"gender'":@"女",@"age":@"18",@"says":@"我爱编程",@"phone":@"7788521",@"imageName":@"1.png"};
//给model类赋值Contecter
Contacter
*contacter =
[[Contacter
alloc]init];
contacter.name
=
dic[@"name"];
//使用KVC赋值
[contacter setValuesForKeysWithDictionary:dic];
cell.photoView.image
=
contacter.image;
cell.nameLabel.text
=
contacter.name;
cell.phoneLabel.text
=
contacter.phone;
NSLog(@"%@-
%@-%@-%@-%@-%@",contacter.name,contacter.age,contacter.gender,contacter.phone,contacter.says,contacter.image);//打印看是否取到Model数据的value值
return
cell;
}
#pragma mark
点击cell触发事件
-
(void)tableView:(UITableView
*)tableView
didSelectRowAtIndexPath:(NSIndexPath
*)indexPath{
DetailContactController
*detailVC =
[[DetailContactController
alloc]init];
[self.navigationController
pushViewController:detailVC
animated:YES];
[detailVC release];
}
//通过代理返回cell的行高
- (CGFloat)tableView:(UITableView
*)tableView
heightForRowAtIndexPath:(NSIndexPath
*)indexPath{
return
90;
"AddContactViewController.h"
#import
"CustomView.h"
@interface
AddContactViewController
()<</span>UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate>
*aview;
@implementation
AddContactViewController
- (void)dealloc{
self.aview
=
nil;
[super
dealloc];
}
- (void)loadView{
self.aview
=
[[CustomView
alloc]initWithFrame:[UIScreen
mainScreen].bounds];
self.view
=
self.aview;
[self.aview
release];
(void)viewDidLoad
{
[super
viewDidLoad];
self.view.backgroundColor
=
[UIColor
cyanColor];
[self
configureNavigationBarContent];
//调用手势方法
[self
addTapGesture];
}
//给aImageView
视图添加轻拍手势
- (void)addTapGesture{
UITapGestureRecognizer
*tap =
[[UITapGestureRecognizer
alloc]initWithTarget:self
action:@selector(handleTap
: )];
[self.aview.aImageView
addGestureRecognizer:tap];
[tap release];
//实现轻拍手势的方法
- (void)handleTap
: (UITapGestureRecognizer
*)tap{
//添加ActionSheet控件
提示选项框
UIActionSheet
*actionSheet =
[[UIActionSheet
alloc]initWithTitle:nil
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:@"拍照"
otherButtonTitles:@"从手机中选择",
nil];
//在当前界面显示actionSheet对象
[actionSheet showInView:self.view];
[actionSheet release];
*)actionSheet
clickeonAtIndex:(NSInteger)buttonIndex{
switch
(buttonIndex)
{
case
0:
//拍照
NSLog(@"拍照");
[self
pickerPictureFromCamera];
break;
case
1:
//从相册中读取照片
NSLog(@"从相册中读取照片");
[self
pickerPictureFormPhotoAlbum];
break;
default:
break;
}
}
//拍照
- (void)pickerPictureFromCamera{
//判断前摄像头是否可以使用
BOOL
isCameera =
[UIImagePickerController
isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront];
//
UIImagePickerControllerCameraDeviceFront
前摄像头
//
UIImagePickerControllerCameraDeviceRear
//后摄像头
if
(!isCameera)
{
NSLog(@"没有摄像头可以使用");
return;
}
//初始化图片选择控制器对象
UIImagePickerController
*imagePicker =
[[UIImagePickerController
alloc]init];
//设置图片选择器选取图片的样式
imagePicker.sourceType
=
UIImagePickerControllerSourceTypePhotoLibrary;
//设置取出来的图片是否允许编辑
imagePicker.allowsEditing
=
YES;
//设置代理
imagePicker.delegate
=
self;
必须同时遵循UIImagePickerControllerDelegate,UINavigationControllerDelegate
两个协议
//把手机相机推出来
[self
presentViewController:imagePicker
animated:YES
completion:nil];
[imagePicker release];
}
- (void)pickerPictureFormPhotoAlbum{
UIImagePickerController
*imagePicker =
[[UIImagePickerController
alloc]init];
//设置图片格式
imagePicker.sourceType
=
UIImagePickerControllerSourceTypePhotoLibrary;
//设置允许编辑
imagePicker.allowsEditing
=
YES;
//设置代理
imagePicker.delegate
=
self;
[self
presentViewController:imagePicker
animated:YES
completion:nil];
[imagePicker release];
(void)imagePickerController:(UIImagePickerController
*)picker
didFinishPickingMediaWithInfo:(NSDictionary
*)info{
//从字典中取出编辑的key值,对应的照片
self.aview.aImageView.image
=
[info objectForKey:UIImagePickerControllerEditedImage];
//自己推出来的自己收回去
[self
dismissViewControllerAnimated:YES
completion:nil];
- (void)configureNavigationBarContent{
self.navigationItem.title
=
@"添加联系人";
//配置导航条背景颜色
self.navigationController.navigationBar.barTintColor
=
[UIColor
orangeColor];
//配置内容页的渲染颜色
self.navigationController.navigationBar.tintColor
=
[UIColor
whiteColor];
//配置字体颜色
NSDictionary
*dic =
@{NSForegroundColorAttributeName
:
[UIColor
whiteColor]};
self.navigationController.navigationBar.titleTextAttributes
=
dic;
//左侧取消按钮
UIBarButtonItem
*leftItem =
[[UIBarButtonItem
alloc]initWithImage:[UIImage
imageNamed:@"clsose"]
style:(UIBarButtonItemStylePlain)
target:self
action:@selector(hanlBack
: )];
self.navigationItem.leftBarButtonItem
=
leftItem;
//释放
[leftItem release];
//右侧保存按钮
UIBarButtonItem
*rightItem =
[[UIBarButtonItem
alloc]initWithImage:[UIImage
imageNamed:@"doneR"]
style:(UIBarButtonItemStylePlain)
target:self
action:@selector(handleSave
: )];
self.navigationItem.rightBarButtonItem
=
rightItem;
#pragma mark
取消按钮的实现
-
(void)hanlBack
: (UIBarButtonItem
*)item{
//返回上一级界面
[self
dismissViewControllerAnimated:YES
completion:nil];
}
#pragma mark
保存按钮的实现
-
(void)handleSave
: (UIBarButtonItem
*)item{
//保存数据操作
//保存数据后同样返回上一个界面
[self
dismissViewControllerAnimated:YES
completion:nil];
"DetailContactController.h"
#import
"CustomView.h"
@interface
DetailContactController
()<</span>UIActionSheetDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate>
@property(nonatomic,retain)CustomView
*aView;
DetailContactController
- (void)dealloc{
self.aView
=
nil;
[super
dealloc];
(void)loadView{
self.aView
=
[[CustomView
alloc]initWithFrame:[UIScreen
mainScreen].bounds];
self.view
=
self.aView;
[self.aView
release];
的交互事件方法
- (void)closeUserInteractionByBool
: (BOOL)isTure{
//根据传进来的参数决定self.aView交互是否打开
self.aView.userInteractionEnabled
= isTure;
(void)viewDidLoad
{
[super
viewDidLoad];
self.view.backgroundColor
=
[UIColor
whiteColor];
//配置导航条的内容
[self
configureNavigationBarContent];
//进来详情页面先不能编辑
[self
closeUserInteractionByBool:NO];
//调用添加手势的方法
[self
addTapGesture];
//添加aImageView添加轻拍手势
- (void)addTapGesture{
UITapGestureRecognizer
*tap =
[[UITapGestureRecognizer
alloc]initWithTarget:self
action:@selector(handleTap
: )];
[self.aView.aImageView
addGestureRecognizer:tap];
[tap
release];
}
//实现轻拍手势的方法
- (void)handleTap
: (UITapGestureRecognizer
*)tap{
UIActionSheet
*actionSheet =
[[UIActionSheet
alloc]initWithTitle:nil
delegate:self
cancelButtonTitle:@"取消"
destructiveButtonTitle:@"拍照"
otherButtonTitles:@"从手机中选择",
nil];
//当前界面显示actionSheet对象
[actionSheet showInView:self.view];
[actionSheet release];
}
- (void)actionSheet:(UIActionSheet
*)actionSheet
clickeonAtIndex:(NSInteger)buttonIndex{
switch
(buttonIndex)
{
case
0:
[self
pickerPictureFromCamera];
NSLog(@"没有摄像头可以使用");
break;
case
1:
[self
pickerPictureFromPhotoAlbum];
break;
default:
break;
}
}
//配置导航条的内容
- (void)configureNavigationBarContent{
self.navigationItem.title
=
@"详情";
//左侧配置编辑按钮
UIBarButtonItem
*leftItem =
[[UIBarButtonItem
alloc]initWithImage:[UIImage
imageNamed:@"btn_backItem"]
style:(UIBarButtonItemStylePlain)
target:self
action:@selector(handleBack:)];
self.navigationItem.leftBarButtonItem
=
leftItem;
[leftItem release];
//配置右侧按钮
self.navigationItem.rightBarButtonItem
=
self.editButtonItem;
//拍照
- (void)pickerPictureFromCamera{
//判断前摄像头是否可以使用
BOOL
isCamera =
[UIImagePickerController
isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront];
if
(!isCamera)
{
return;
}
//初始化图片是选择器对象
UIImagePickerController
*imagePicker =
[[UIImagePickerController
alloc]init];
//设置图片选择器选取图片的样式
imagePicker.sourceType
=
UIImagePickerControllerSourceTypePhotoLibrary;
//设置取出来的图片是否允许编辑
imagePicker.allowsEditing
= YES;
//设置代理
imagePicker.delegate
=
self;
//把手机相机推出来
[self
presentViewController:imagePicker
animated:YES
completion:nil];
[imagePicker release];
//从相册中取相片
- (void)pickerPictureFromPhotoAlbum{
UIImagePickerController
*imagePicker =
[[UIImagePickerController
alloc]init];
//设置图片格式
imagePicker.sourceType
=
UIImagePickerControllerSourceTypePhotoLibrary;
//设置是否允许编辑
imagePicker.allowsEditing
=
YES;
//设置代理
imagePicker.delegate
=
self;
[self
presentViewController:imagePicker
animated:YES
completion:nil];
}
- (void)imagePickerController:(UIImagePickerController
*)picker
didFinishPickingMediaWithInfo:(NSDictionary
*)info{
//从字典中取出编辑的key值,对应的照片
self.aView.aImageView.image
=
[info objectForKey:UIImagePickerControllerEditedImage];
//自己推出来自己收回去
[self
dismissViewControllerAnimated:YES
completion:nil];
重写编辑按钮的方法
(void)setEditing:(BOOL)editing
animated:(BOOL)animated{
[super
setEditing:editing
animated:animated];
//调用交互的方法
//editing ==
YES 可以编辑 editing == NO
不可以编辑
[self
closeUserInteractionByBool:editing];
- (void)handleBack:
(UIBarButtonItem
*)back{
//保存数据的方法
//返回上一个界面
[self.navigationController
popViewControllerAnimated:YES];
自定义cell和自定义视图布局不做详细介绍!
*photoView;
@property(nonatomic,retain)UILabel
*nameLabel;
*phoneLabel;
(id)initWithStyle:(UITableViewCellStyle)style
reuseIdentifier:(NSString
*)reuseIdentifier{
if
(self
=
[super
initWithStyle:style
reuseIdentifier:reuseIdentifier])
{
//布局操作写在这里
[self.contentView
addSubview:self.photoView];
[self.contentView
addSubview:self.nameLabel];
[self.contentView
addSubview:self.phoneLabel];
}
return
self;
(UIImageView
*)photoView{
if
(_photoView
==
nil)
{
self.photoView
=
[[[UIImageView
alloc]initWithFrame:CGRectMake(10,
5,
80,
80)]autorelease];
self.photoView.layer.cornerRadius
=
40.0;
self.photoView.layer.masksToBounds
=
YES;
self.photoView.backgroundColor
=
[UIColor
brownColor];
}
//添加安全机制
return
[[_photoView
retain]autorelease];
注意:系统提供的持有对象有时也会crash所以retain再release更安全!
(UILabel
*)nameLabel{
if
(_nameLabel
==
nil)
{
self.nameLabel
=
[[[UILabel
alloc]initWithFrame:CGRectMake(100,
18,
100,
25)]autorelease];
self.nameLabel.backgroundColor
=
[UIColor
brownColor];
self.nameLabel.layer.cornerRadius
=
7;
self.nameLabel.layer.masksToBounds
=
YES;
}
return
[[_nameLabel
retain]autorelease];
}
- (UILabel
*)phoneLabel{
if
(_phoneLabel
==
nil)
{
self.phoneLabel
=
[[[UILabel
alloc]initWithFrame:CGRectMake(100,
48,
160,
25)]autorelease];
self.phoneLabel.backgroundColor
=
[UIColor
brownColor];
self.phoneLabel.layer.cornerRadius
=
7;
self.phoneLabel.layer.masksToBounds
=
YES;
}
return
[[_phoneLabel
retain]autorelease];
实战项目:通讯录 UI—第十一天的更多相关文章
- .NET Core实战项目之CMS 第十一章 开发篇-数据库生成及实体代码生成器开发
上篇给大家从零开始搭建了一个我们的ASP.NET Core CMS系统的开发框架,具体为什么那样设计我也已经在第十篇文章中进行了说明.不过文章发布后很多人都说了这样的分层不是很合理,什么数据库实体应该 ...
- .NET Core实战项目之CMS 第十三章 开发篇-在MVC项目结构介绍及应用第三方UI
作为后端开发的我来说,前端表示真心玩不转,你如果让我微调一个位置的样式的话还行,但是让我写一个很漂亮的后台的话,真心做不到,所以我一般会选择套用一些开源UI模板来进行系统UI的设计.那如何套用呢?今天 ...
- .NET Core实战项目之CMS 第一章 入门篇-开篇及总体规划
作者:依乐祝 原文地址:https://www.cnblogs.com/yilezhu/p/9977862.html 写在前面 千呼万唤始出来,首先,请允许我长吸一口气!真没想到一份来自28岁老程序员 ...
- android经典实战项目视频教程下载
注:这是一篇转载的文章,原文具体链接地址找不到了,将原文分享如下,希望能对看到的朋友有所帮助! 最近在学习android应用方面的技术,自己在网上搜集了一些实战项目的资料,感觉挺好的,发布出来跟大伙分 ...
- vue+websocket+express+mongodb实战项目(实时聊天)
继上一个项目用vuejs仿网易云音乐(实现听歌以及搜索功能)后,发现上一个项目单纯用vue的model管理十分混乱,然后我去看了看vuex,打算做一个项目练练手,又不想做一个重复的项目,这次我就放弃颜 ...
- .NET Core实战项目之CMS 第二章 入门篇-快速入门ASP.NET Core看这篇就够了
作者:依乐祝 原文链接:https://www.cnblogs.com/yilezhu/p/9985451.html 本来这篇只是想简单介绍下ASP.NET Core MVC项目的(毕竟要照顾到很多新 ...
- .NET Core实战项目之CMS 第十章 设计篇-系统开发框架设计
这两天比较忙,周末也在加班,所以更新的就慢了一点,不过没关系,今天我们就进行千呼万唤的系统开发框架的设计.不知道上篇关于架构设计的文章大家有没有阅读,如果阅读后相信一定对架构设计有了更近一部的理解,如 ...
- Web项目开发介绍及实战项目介绍
引言 本系列课程我们将学些Golang语言中的Web开发框架Iris的相关知识和用法.通过本系列视频课程,大家能够从零到一经历一个完整项目的开发,并在课程中了解实战项目开发的流程和项目设涉及的各个模块 ...
- react实战项目-很适合进阶
前言 前段时间学习完了React的基础,自己网上找了一些实战项目,做了几个感觉项目不是很全面,就想做一个完整的项目来提升自己的React水平.以前学习Vue的时候,就看过bailicangdu大神的v ...
随机推荐
- CentOS 7 配置网络连接
在VMware workstation12上新建虚拟机,发现无法连接网络.然后查了一些资料,知道了怎样配置网络,记录一下. 1.首先用ifconfig命令查看虚拟机的IP地址及网关信息 观察显示内容, ...
- Ubuntu安装与配置KVM
事前检查 查看一下linux是32位还是64位 file /bin/ls 确认一下 CPU支持硬件虚拟化(不支持也没关系,可以继续) egrep -o '(vmx|svm)' /proc/cpuinf ...
- Oracle中的列转行例子详解
数据如下:name id张三 1,2,3 要求实现:name id张三 1张三 2张三 3 --创建临时表 create table tmp as(select '张三' name, '1,2,3' ...
- Java并发编程(一)-为什么要并发
并发所带来的好处 1. 并发在某些情况(并不是所有情况)下可以带来性能上的提升 1) 提升对CPU的使用效率 提升多核CPU的利用率:一般来说一台主机上的会有多个CPU核心,我们可以创建多个线程,理论 ...
- iOS图形手势识别框架SGGestureRecognizer
简介 苹果官方为我们提供了简单手势的识别器,但对于图形手势,例如五角星.三角形等的识别,就需要自己实现了.通过识别这些手势,可以去执行特定的操作,或是输入公式.释放魔法等,可以为App增光添彩. 下载 ...
- SQL批处理与事务控制
今天我想要分享的是关于数据库的批处理与事务的控制.批处理对于项目的实际应用有非常大的具体意义. 一.批处理部分 首先我们新建一个表: create table t3( id int primary k ...
- 剑指Offer——常用SQL语句、存储过程和函数
剑指Offer--常用SQL语句.存储过程和函数 常用SQL语句 1.在MySQL数据库建立多对多的数据表关系 2.授权.取消授权 grant.revoke grant select, insert, ...
- Team Foundation Server 2015 Update 2.1 发布日志
微软在 2016年5月5日发布了Visual Studio Team Foundation Server 2015 update 2.1. 下面我们来看看Update2.1中给我们带来了哪些新功能. ...
- CUSTOM.PLL的使用
在开发中对系统标准form的修改一般不建议修改系统原有FORM,对所需要修改的内容一般写在CUSTOM.PLL里即可,应为每个form运行的时候都会调用CUSTOM.PLL具体概念性东西可参考网上资料 ...
- SSH网上商城---使用ajax完成用户名是否存在异步校验
小伙伴在上网的时候,需要下载或者观看某些视频资料,更或者是在逛淘宝的时候,我们都需要注册一个用户,当我们填写好各种信息,点击确定的时候,提示用户名已经存在,小编就想,为什么当我们填写完用户名的时候,她 ...