******HMLoginViewController 登陆的界面

#import "HMLoginViewController.h"

#import "MBProgressHUD+MJ.h"

#import "HMContactsTableViewController.h"

@interface HMLoginViewController ()<UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UITextField *accountField;
@property (weak, nonatomic) IBOutlet UITextField *pwdField;
@property (weak, nonatomic) IBOutlet UIButton *loginBtn;
@property (weak, nonatomic) IBOutlet UISwitch *autoLoginS;
@property (weak, nonatomic) IBOutlet UISwitch *rmbPwdS; @property (nonatomic, strong) HMContactsTableViewController *contact;
@end
@implementation HMLoginViewController
#warning 第四步做跳转之前的准备工作
/**
* 执行segue的时候,跳转之前调用
* 一般用做一些跳转之前的准备操作,给下一个控制器传值
* @param segue <#segue description#>
* @param sender <#sender description#>
*/
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{ // NSLog(@"%@---%@--%@",segue.identifier,segue.sourceViewController,segue.destinationViewController); // 获取目的控制器
UIViewController *v = segue.destinationViewController; // 给联系人导航条设置标题
v.navigationItem.title = [NSString stringWithFormat:@"%@的联系人",_accountField.text]; }
#warning 第三步处理登录功能
// 当点击登录的时候调用
- (IBAction)login:(id)sender { // hm 123 // 判断用户输入的账号和密码是否正确
if ([_accountField.text isEqualToString:@"hm"] && [_pwdField.text isEqualToString:@""]) { // 账号和密码正确 // 显示遮盖:只要做一些比较耗时的操作最好用遮盖
[MBProgressHUD showMessage:@"正在登录中"]; // GCD
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// 移除遮盖
[MBProgressHUD hideHUD];
// 执行segue
[self performSegueWithIdentifier:@"login2contact" sender:nil];
}); }else{ // 不正确 // MBProgressHud:提示框
[MBProgressHUD showError:@"账号或者密码错误"];
}
}
#warning 第二步 处理Switch
// 当记住密码状态改变的时候调用
- (IBAction)rmbPwdSwitch:(UISwitch *)sender {
//
if (sender.isOn == NO) {
[_autoLoginS setOn:NO animated:YES]; } }
// 当自动登录状态改变的时候调用
- (IBAction)autoLoginSwitch:(UISwitch *)sender {
if (sender.isOn == YES) {
[_rmbPwdS setOn:YES animated:YES];
} }
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view. #warning 第一步监听两个文本框的内容,控制器登录按钮的状态
// 1.addTarget
[_accountField addTarget:self action:@selector(textChange) forControlEvents:UIControlEventEditingChanged];
[_pwdField addTarget:self action:@selector(textChange) forControlEvents:UIControlEventEditingChanged]; // 手动判断按钮是否能点击
[self textChange];
}
// 当文本框的内容改变的时候就会调用
- (void)textChange
{
// 判断两个文本框的内容
_loginBtn.enabled = _accountField.text.length && _pwdField.text.length;
}
@end

*************HMContactsTableViewController.m联系人的界面

#import "HMContactsTableViewController.h"
#import "HMAddViewController.h" #import "HMEditViewController.h" #import "HMContactCell.h" #import "HMContact.h"
@interface HMContactsTableViewController ()<UIActionSheetDelegate,HMAddViewControllerDelgegate,HMEditViewControllerDelegate> @property (nonatomic, strong) NSMutableArray *contacts;
@end
@implementation HMContactsTableViewController
#warning 第五步操作
#pragma mark - 注销功能
// 点击注销就会调用这个方法
- (IBAction)logout:(id)sender { UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"是否注销?" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"注销" otherButtonTitles:nil, nil]; [sheet showInView:self.view]; }
- (NSMutableArray *)contacts
{
if (_contacts == nil) {
_contacts = [NSMutableArray array];
}
return _contacts;
} - (void)setName:(NSString *)name phone:(NSString *)phone
{
NSLog(@"%@---%@",name,phone);
}
/**
* 跳转之前,调用这个方法
*/
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NSLog(@"%@",segue.destinationViewController); if ([segue.destinationViewController isKindOfClass:[HMAddViewController class]]) { HMAddViewController *vc = segue.destinationViewController; vc.delegate = self;
}else{ // 跳转到编辑控制器
HMEditViewController *edit = segue.destinationViewController; NSIndexPath *seletedIndex = [self.tableView indexPathForSelectedRow]; edit.delegate = self;
edit.contact = self.contacts[seletedIndex.row]; } } // 成功更新了一个联系人的时候调用
- (void)editViewController:(HMEditViewController *)edit didUpdateContact:(HMContact *)contact
{
// 刷新表格
[self.tableView reloadData];
} // 成功添加了一个联系人的时候调用
- (void)addViewController:(HMAddViewController *)add didAddContact:(HMContact *)contact
{
// 保存
[self.contacts addObject:contact]; // 刷新表格
[self.tableView reloadData];
} - (void)viewDidLoad
{
[super viewDidLoad]; // 移除分割线
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; } #pragma mark - Table view data source - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return self.contacts.count;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{ // 1.创建对象
HMContactCell *cell = [HMContactCell cellWithTableView:tableView]; // 2.传递模型
cell.contact = self.contacts[indexPath.row]; return cell;
} - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex) return; // 回到登录界面
[self.navigationController popViewControllerAnimated:YES];
} @end

************联系人的cell的界面 HMContactCell.m

#import "HMContactCell.h"
#import "HMContact.h" @interface HMContactCell() @property (nonatomic, weak) UIView *divide; @end @implementation HMContactCell - (UIView *)divide
{
if (_divide == nil) { UIView *v = [[UIView alloc] init]; v.backgroundColor = [UIColor blackColor]; v.alpha = 0.2;
_divide = v; [self.contentView addSubview:_divide];
} return _divide;
} - (void)setContact:(HMContact *)contact
{
_contact = contact; // 给cell的控件赋值
self.textLabel.text = contact.name;
self.detailTextLabel.text = contact.phone; } + (instancetype)cellWithTableView:(UITableView *)tableView
{
static NSString *ID = @"contact";
return [tableView dequeueReusableCellWithIdentifier:ID]; } // 从XIB加载完成的时候调用
- (void)awakeFromNib
{
// Initialization code }
// 当自己的frame改变的时候就会调用
- (void)layoutSubviews
{
[super layoutSubviews];
// 给divide设置位置
CGFloat divideH = ;
CGFloat divideW = self.bounds.size.width;
CGFloat divideY = self.bounds.size.height - divideH;
self.divide.frame = CGRectMake(, divideY, divideW, divideH); } - (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated]; // Configure the view for the selected state
} @end

************联系人的cell的界面 HMContactCell.h

#import <UIKit/UIKit.h>
@class HMContact;
@interface HMContactCell : UITableViewCell @property (nonatomic, strong) HMContact *contact; + (instancetype)cellWithTableView:(UITableView *)tableView; @end

************编辑的界面 HMEditViewController.m

#import "HMEditViewController.h"

#import "HMContact.h"

@interface HMEditViewController ()
@property (weak, nonatomic) IBOutlet UITextField *nameField;
@property (weak, nonatomic) IBOutlet UITextField *phoneField;
@property (weak, nonatomic) IBOutlet UIButton *saveBtn; @end @implementation HMEditViewController // 点击了保存按钮
- (IBAction)save:(id)sender {
// 1.回到联系人界面
[self.navigationController popViewControllerAnimated:YES];
// 2.更新数据:覆盖旧数据,把最新的数据展示出来
self.contact.name = _nameField.text;
self.contact.phone = _phoneField.text; // 3.通知联系人界面刷新表格
if ([_delegate respondsToSelector:@selector(editViewController:didUpdateContact:)]) {
[_delegate editViewController:self didUpdateContact:self.contact];
} } // 点击了编辑按钮就会调用
- (IBAction)edit:(UIBarButtonItem *)sender { if ([sender.title isEqualToString:@"取消"]) { // 点击取消
// 1.改变按钮的文字
sender.title = @"编辑";
// 2.不允许文本框编辑
_nameField.enabled = NO;
_phoneField.enabled = NO; // 3.隐藏保存按钮
_saveBtn.hidden = YES; // 4.退出键盘
// [_phoneField resignFirstResponder];
[self.view endEditing:YES]; // 恢复文本框显示
_nameField.text = _contact.name;
_phoneField.text = _contact.phone; }else // 点击编辑
{
// 1.改变按钮的文字
sender.title = @"取消";
// 2.允许文本框编辑
_nameField.enabled = YES;
_phoneField.enabled = YES; // 3.显示保存按钮
_saveBtn.hidden = NO; // 4.弹出电话的键盘
[_phoneField becomeFirstResponder]; } } #pragma mark 给文本框控件赋值
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view. // 给控件赋值
_nameField.text = _contact.name;
_phoneField.text = _contact.phone; // 1.addTarget
[_nameField addTarget:self action:@selector(textChange) forControlEvents:UIControlEventEditingChanged];
[_phoneField addTarget:self action:@selector(textChange) forControlEvents:UIControlEventEditingChanged]; // 手动判断按钮是否能点击
[self textChange];
} - (void)textChange
{
// 判断两个文本框的内容
_saveBtn.enabled = _nameField.text.length && _phoneField.text.length; } @end

************编辑的界面 HMEditViewController.h

#import <UIKit/UIKit.h>

@class HMContact,HMEditViewController;

@protocol HMEditViewControllerDelegate <NSObject>

@optional
- (void)editViewController:(HMEditViewController *)edit didUpdateContact:(HMContact *)contact; @end @interface HMEditViewController : UIViewController @property (nonatomic, strong) HMContact *contact; @property (nonatomic, weak) id<HMEditViewControllerDelegate> delegate; @end

*****联系人的model  HMContact.m

#import "HMContact.h"

@implementation HMContact

// instancetype自动识别当前类的对象 == HMContact *
+ (instancetype)contactWithName:(NSString *)name phone:(NSString *)phone
{
HMContact *contact = [[HMContact alloc] init]; contact.name = name;
contact.phone = phone; return contact;
} @end

******HMContact.h

#import <Foundation/Foundation.h>

@interface HMContact : NSObject

@property (nonatomic, copy) NSString *name;

@property (nonatomic, copy) NSString *phone;

+ (instancetype)contactWithName:(NSString *)name phone:(NSString *)phone;

@end

IOS第13天(1,私人通讯录,登陆功能,界面的跳转传值,自定义cell,编辑界面)的更多相关文章

  1. IOS第13天(3,私人通讯录,登陆状态数据存储,数据缓存, cell的滑动删除,进入编辑模式,单个位置刷新 )

    *****联系人的界面的优化 HMContactsTableViewController.m #import "HMContactsTableViewController.h" # ...

  2. IOS第13天(2,私人通讯录,plist存储,偏好设置,归档)

    ***************plist存储 // 当点点击保存的时候调用 //保存 - (IBAction)save:(id)sender { // 获取沙盒的根路径 // NSString *ho ...

  3. iOS 11开发教程(六)iOS11Main.storyboard文件编辑界面

    iOS 11开发教程(六)iOS11Main.storyboard文件编辑界面 在1.2.2小节中提到过编辑界面(Interface builder),编辑界面是用来设计用户界面的,单击打开Main. ...

  4. iOS 9应用开发教程之编辑界面与编写代码

    iOS 9应用开发教程之编辑界面与编写代码 编辑界面 在1.2.2小节中提到过编辑界面(Interface builder),编辑界面是用来设计用户界面的,单击打开Main.storyboard文件就 ...

  5. [iOS基础控件 - 6.11.3] 私人通讯录Demo 控制器的数据传递、存储

    A.需求 1.搭建一个"私人通讯录"Demo 2.模拟登陆界面 账号 密码 记住密码开关 自动登陆开关 登陆按钮 3.退出注销 4.增删改查 5.恢复数据(取消修改)   这个代码 ...

  6. IOS学习之-私人通讯录

    通过一段时间IOS的学习完成了一个简单的应用,"私人通讯录". 运行效果如下图: 1.登录页 2.通讯录列表 3.添加 4.编辑 5.删除 6.注销 总视图结构如下图: 总结本程序 ...

  7. 搭建私人通讯录/日历同步服务_使用cardDAV/calDAV服务

    搭建私人通讯录/日历同步服务_使用cardDAV/calDAV服务 转载注明来源: 本文链接 来自osnosn的博客,写于 2020-02-18. Radicale, Radicale (对cardd ...

  8. .NET平台开源项目速览(13)机器学习组件Accord.NET框架功能介绍

    Accord.NET Framework是在AForge.NET项目的基础上封装和进一步开发而来.因为AForge.NET更注重与一些底层和广度,而Accord.NET Framework更注重与机器 ...

  9. 从零开始编写自己的C#框架(15)——Web层后端登陆功能

    对于一个后端管理系统,最重要内容之一的就是登陆页了,无论是安全验证.用户在线记录.相关日志记录.单用户或多用户使用帐号控制等,都是在这个页面进行处理的. 1.在解决方案中创建一个Web项目,并将它设置 ...

随机推荐

  1. TestNg依赖详解(三)------灵活的文件配置依赖

    配置型的依赖测试,让依赖测试不局限于测试代码中,在XML文件中进行灵活的依赖配置 原创文章,版权所有,允许转载,标明出处:http://blog.csdn.net/wanghantong Javaco ...

  2. NoSQL-Redis【2】-实现分布式Session

    经过一周紧张的开发和调试,终于把Redis实现的分布式Session发布到了生产环境.我在本地测试了100万的数据,Redis的速度确实让我满意,期待在线上有更好的表现. 一.配置windows-se ...

  3. java-嵌套类

    浏览以下内容前,请点击并阅读 声明 java允许在一个类中定义另外一个类,这就叫类嵌套.类嵌套分为两种,静态的称为静态嵌套类,非静态的又称为内部类. 使用嵌套类的原因: 能够将仅在一个地方使用的类合理 ...

  4. Drawing Arc Using ArcSegment in XAML

    We can use the Arc XAML element to draw arcs in XAML. Besides drawing arcs using the Arc element, we ...

  5. [R语言]forecast.Arima中使用xreg报错

    问题: 使用forecast.Arima对带xreg的arima模型进行预测,报xreg Error pre.m4x <- forecast.Arima(m4x, h = 20, xreg = ...

  6. Java NIO之选择器Selector

    在单独的线程中,检查多个通道是否可以进行IO操作. Selector创建:静态工厂方法创建 Selector selector = Selector.open(); 注册通道 channel.conf ...

  7. 2017亚洲VR&AR博览会暨高峰论坛

    2017亚洲VR&AR博览会暨高峰论坛 2017 Asia VR&AR Fair & Summit(VR&AR Fair 2017) 活动介绍活动时间: 2017年3月 ...

  8. ACM Haffman编码

    Haffman编码 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 哈弗曼编码大家一定很熟悉吧(不熟悉也没关系,自己查去...).现在给你一串字符以及它们所对应的权值 ...

  9. CF 22B. Bargaining Table

    水题.好久没有写过优化搜索题了. #include <cstdio> #include <cstring> #include <iostream> #include ...

  10. URAL 1427. SMS(DP+单调队列)

    题目链接 我用的比较传统的办法...单调队列优化了一下,写的有点搓,不管怎样过了...两个单调队列,存两个东西,预处理一个标记数组存... #include <iostream> #inc ...