forked from BigShow1949/BigShow1949
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3d37fcb
commit e163b25
Showing
17 changed files
with
291 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+14.5 KB
(180%)
BigShow1949.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
Binary file not shown.
14 changes: 14 additions & 0 deletions
14
BigShow1949/Classes/12 - DesignPattern(设计模式)/MVP_Login/HttpUtils.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// HttpUtils.h | ||
// Dream_Architect_MVP_OC | ||
// | ||
// Created by Apple on 2017/2/7. | ||
// Copyright © 2017年 乔布永. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
typedef void(^Callback) (NSString* result); | ||
@interface HttpUtils : NSObject | ||
+ (void)postWithName:(NSString*)name pwd:(NSString*)pwd callback:(Callback)callback; | ||
|
||
@end |
47 changes: 47 additions & 0 deletions
47
BigShow1949/Classes/12 - DesignPattern(设计模式)/MVP_Login/HttpUtils.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// | ||
// HttpUtils.m | ||
// Dream_Architect_MVP_OC | ||
// | ||
// Created by Apple on 2017/2/7. | ||
// Copyright © 2017年 乔布永. All rights reserved. | ||
// | ||
|
||
#import "HttpUtils.h" | ||
|
||
@implementation HttpUtils | ||
+ (void)postWithName:(NSString*)name pwd:(NSString*)pwd callback:(Callback)callback{ | ||
//发起网络请求 | ||
//第三方框架(这地方网络框架既能调用系统,又能调用第三方的框架) | ||
//希望做一个这样的处理(方便后期的维护和扩展) | ||
//直接调用系统吧 | ||
//第一步: | ||
NSURL *url = [NSURL URLWithString:@"http://42.120.11.155/index.php?m=home&c=user&a=login"]; | ||
//第二步: | ||
NSMutableURLRequest * request = [[NSMutableURLRequest alloc]initWithURL:url]; | ||
//第三步: | ||
request.HTTPMethod = @"POST"; | ||
NSString *params = [NSString stringWithFormat:@"mobile=%@&password=%@",name,pwd]; | ||
request.HTTPBody = [params dataUsingEncoding:NSUTF8StringEncoding]; | ||
//第四步: | ||
//创建请求会话 | ||
NSURLSession *session = [NSURLSession sharedSession]; | ||
//第五步:创建请求任务 | ||
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) { | ||
//第七步:处理请求结果 | ||
if (error!=nil) { | ||
NSLog(@"登录失败"); | ||
}else{ | ||
|
||
NSLog(@"登录成功"); | ||
//回调 | ||
NSString *result = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding]; | ||
callback(result); | ||
|
||
} | ||
}]; | ||
// 第六步:执行任务 | ||
[task resume]; | ||
|
||
} | ||
|
||
@end |
16 changes: 16 additions & 0 deletions
16
BigShow1949/Classes/12 - DesignPattern(设计模式)/MVP_Login/LoginModel.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// | ||
// LoginModel.h | ||
// BigShow1949 | ||
// | ||
// Created by apple on 17/8/11. | ||
// Copyright © 2017年 BigShowCompany. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "HttpUtils.h" | ||
|
||
//M层(数据层,数据库,网络,文件等...) | ||
@interface LoginModel : NSObject | ||
//业务方法 | ||
- (void)loginWithName:(NSString*)name pwd:(NSString*)pwd callback:(Callback)callback; | ||
@end |
24 changes: 24 additions & 0 deletions
24
BigShow1949/Classes/12 - DesignPattern(设计模式)/MVP_Login/LoginModel.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// LoginModel.m | ||
// BigShow1949 | ||
// | ||
// Created by apple on 17/8/11. | ||
// Copyright © 2017年 BigShowCompany. All rights reserved. | ||
// | ||
|
||
#import "LoginModel.h" | ||
|
||
@implementation LoginModel | ||
- (void)loginWithName:(NSString*)name pwd:(NSString*)pwd callback:(Callback)callback{ | ||
//实现功能 | ||
//例如:访问网络?访问数据库? | ||
//数据曾划分了模块() | ||
[HttpUtils postWithName:name pwd:pwd callback:^(NSString *result) { | ||
//解析json ,xml数据 | ||
//然后保存数据库 | ||
//中间省略100行代码 | ||
callback(result);//返回数据回调 | ||
}]; | ||
} | ||
|
||
@end |
20 changes: 20 additions & 0 deletions
20
BigShow1949/Classes/12 - DesignPattern(设计模式)/MVP_Login/LoginPresenter.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// LoginPresenter.h | ||
// BigShow1949 | ||
// | ||
// Created by apple on 17/8/11. | ||
// Copyright © 2017年 BigShowCompany. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
#import "LoginViewProtocol.h" | ||
#import "LoginModel.h" | ||
// P层 | ||
//中介(用于关联M层和V层) | ||
@interface LoginPresenter : NSObject | ||
|
||
//提供一个业务方法 | ||
- (void)loginWithName:(NSString*)name pwd:(NSString*)pwd; | ||
- (void)attachView:(id<LoginViewProtocol>)loginView; | ||
- (void)detachView; | ||
@end |
49 changes: 49 additions & 0 deletions
49
BigShow1949/Classes/12 - DesignPattern(设计模式)/MVP_Login/LoginPresenter.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// | ||
// LoginPresenter.m | ||
// BigShow1949 | ||
// | ||
// Created by apple on 17/8/11. | ||
// Copyright © 2017年 BigShowCompany. All rights reserved. | ||
// | ||
|
||
#import "LoginPresenter.h" | ||
|
||
|
||
//P是中介(职责是用于关联M和V) | ||
//P层需要:持有M层的引用和V层的引用(OOP)思想 | ||
@interface LoginPresenter () | ||
@property (nonatomic,strong) LoginModel *loginModel; | ||
@property (nonatomic,strong) id<LoginViewProtocol> loginView; | ||
@end | ||
|
||
|
||
@implementation LoginPresenter | ||
- (instancetype)init{ | ||
self = [super init]; | ||
if (self) { | ||
//持有M层的引用 | ||
_loginModel = [[LoginModel alloc]init]; | ||
} | ||
return self; | ||
} | ||
//提供绑定V层方法 | ||
//绑定 | ||
- (void)attachView:(id<LoginViewProtocol>)loginView{ | ||
_loginView = loginView; | ||
} | ||
//解除绑定 | ||
- (void)detachView{ | ||
_loginView = nil; | ||
} | ||
//实现业务方法 | ||
- (void)loginWithName:(NSString*)name pwd:(NSString*)pwd{ | ||
[_loginModel loginWithName:name pwd:pwd callback:^(NSString *result) { | ||
if (_loginView != nil) { | ||
[_loginView onLoginResult:result]; | ||
} | ||
}]; | ||
|
||
} | ||
|
||
|
||
@end |
15 changes: 15 additions & 0 deletions
15
BigShow1949/Classes/12 - DesignPattern(设计模式)/MVP_Login/LoginViewProtocol.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// LoginViewProtocal.h | ||
// BigShow1949 | ||
// | ||
// Created by apple on 17/8/11. | ||
// Copyright © 2017年 BigShowCompany. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
//V层 | ||
@protocol LoginViewProtocol <NSObject> | ||
|
||
- (void)onLoginResult:(NSString*)result; | ||
@end |
13 changes: 13 additions & 0 deletions
13
BigShow1949/Classes/12 - DesignPattern(设计模式)/MVP_Login/MVPLoginViewController.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// MVPLoginViewController.h | ||
// BigShow1949 | ||
// | ||
// Created by apple on 17/8/11. | ||
// Copyright © 2017年 BigShowCompany. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
@interface MVPLoginViewController : UIViewController | ||
|
||
@end |
52 changes: 52 additions & 0 deletions
52
BigShow1949/Classes/12 - DesignPattern(设计模式)/MVP_Login/MVPLoginViewController.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// MVPLoginViewController.m | ||
// BigShow1949 | ||
// | ||
// Created by apple on 17/8/11. | ||
// Copyright © 2017年 BigShowCompany. All rights reserved. | ||
// | ||
|
||
#import "MVPLoginViewController.h" | ||
#import "LoginViewProtocol.h" | ||
#import "LoginPresenter.h" | ||
|
||
@interface MVPLoginViewController ()<LoginViewProtocol> | ||
@property (nonatomic,strong) LoginPresenter* presenter; | ||
|
||
@end | ||
|
||
@implementation MVPLoginViewController | ||
|
||
- (void)viewDidLoad { | ||
[super viewDidLoad]; | ||
self.view.backgroundColor = [UIColor whiteColor]; | ||
|
||
// 模拟登录按钮点击 | ||
UIButton *redBtn = [[UIButton alloc] init]; | ||
redBtn.frame = CGRectMake(100, 100, 100, 100); | ||
[redBtn setTitle:@"登 录" forState:UIControlStateNormal]; | ||
[redBtn addTarget:self action:@selector(loginClick) forControlEvents:UIControlEventTouchUpInside]; | ||
redBtn.backgroundColor = [UIColor redColor]; | ||
[self.view addSubview:redBtn]; | ||
|
||
} | ||
|
||
- (void)loginClick { | ||
_presenter = [[LoginPresenter alloc ]init]; | ||
[_presenter attachView:self]; | ||
//程序一旦运行立马执行请求(测试)(按钮或者事件) | ||
[_presenter loginWithName:@"18842693828" pwd:@"123456"]; | ||
} | ||
|
||
- (void)onLoginResult:(NSString *)result{ | ||
|
||
NSLog(@"返回结果 = %@",result); | ||
|
||
} | ||
|
||
- (void)didReceiveMemoryWarning { | ||
[super didReceiveMemoryWarning]; | ||
[_presenter detachView]; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,4 +10,7 @@ | |
|
||
@interface MyDataSourceViewController : UIViewController | ||
|
||
/* | ||
内容不多, 就不创建文件了, 全部都放在一个文件目录下 | ||
*/ | ||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters