Skip to content

Commit

Permalink
implement MVVM
Browse files Browse the repository at this point in the history
  • Loading branch information
DHUsesAll committed Jul 23, 2015
1 parent 5a1fbb7 commit ebf04c8
Show file tree
Hide file tree
Showing 21 changed files with 571 additions and 132 deletions.
30 changes: 30 additions & 0 deletions DeepBreathing.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
E509059D1B5C9551000FB9FE /* DHChatTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = E50905871B5C9551000FB9FE /* DHChatTextField.m */; };
E509059E1B5C9551000FB9FE /* DHPickerTextField.m in Sources */ = {isa = PBXBuildFile; fileRef = E50905891B5C9551000FB9FE /* DHPickerTextField.m */; };
E50905A11B5C9D3C000FB9FE /* ForgetViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E50905A01B5C9D3C000FB9FE /* ForgetViewController.m */; };
E52A755F1B6078DE00090038 /* NetworkingManager+Knowledge.m in Sources */ = {isa = PBXBuildFile; fileRef = E52A755E1B6078DE00090038 /* NetworkingManager+Knowledge.m */; };
E52A75621B60822500090038 /* KnowledgeModel.m in Sources */ = {isa = PBXBuildFile; fileRef = E52A75611B60822500090038 /* KnowledgeModel.m */; };
E52A75651B6087B600090038 /* KnowledgeCell.m in Sources */ = {isa = PBXBuildFile; fileRef = E52A75641B6087B600090038 /* KnowledgeCell.m */; };
E52A75681B60913A00090038 /* KnowledgeViewModel.m in Sources */ = {isa = PBXBuildFile; fileRef = E52A75671B60913A00090038 /* KnowledgeViewModel.m */; };
E556A7C91B55F89A007CFCF5 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E556A7C81B55F89A007CFCF5 /* main.m */; };
E556A7CC1B55F89A007CFCF5 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E556A7CB1B55F89A007CFCF5 /* AppDelegate.m */; };
E556A7CF1B55F89A007CFCF5 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E556A7CE1B55F89A007CFCF5 /* ViewController.m */; };
Expand Down Expand Up @@ -235,6 +239,7 @@
E5D5FA061B5F619400D73C0B /* 急性发作.png in Resources */ = {isa = PBXBuildFile; fileRef = E5D5F9F61B5F619400D73C0B /* 急性发作.png */; };
E5D5FA071B5F619400D73C0B /* 错.png in Resources */ = {isa = PBXBuildFile; fileRef = E5D5F9F71B5F619400D73C0B /* 错.png */; };
E5D5FA081B5F619400D73C0B /* 错_选中.png in Resources */ = {isa = PBXBuildFile; fileRef = E5D5F9F81B5F619400D73C0B /* 错_选中.png */; };
E5D5FA0B1B5F6D5500D73C0B /* QuestionBaseView.m in Sources */ = {isa = PBXBuildFile; fileRef = E5D5FA0A1B5F6D5500D73C0B /* QuestionBaseView.m */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand Down Expand Up @@ -290,6 +295,14 @@
E50905891B5C9551000FB9FE /* DHPickerTextField.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DHPickerTextField.m; sourceTree = "<group>"; };
E509059F1B5C9D3C000FB9FE /* ForgetViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ForgetViewController.h; sourceTree = "<group>"; };
E50905A01B5C9D3C000FB9FE /* ForgetViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ForgetViewController.m; sourceTree = "<group>"; };
E52A755D1B6078DE00090038 /* NetworkingManager+Knowledge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NetworkingManager+Knowledge.h"; sourceTree = "<group>"; };
E52A755E1B6078DE00090038 /* NetworkingManager+Knowledge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NetworkingManager+Knowledge.m"; sourceTree = "<group>"; };
E52A75601B60822500090038 /* KnowledgeModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KnowledgeModel.h; sourceTree = "<group>"; };
E52A75611B60822500090038 /* KnowledgeModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KnowledgeModel.m; sourceTree = "<group>"; };
E52A75631B6087B600090038 /* KnowledgeCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KnowledgeCell.h; sourceTree = "<group>"; };
E52A75641B6087B600090038 /* KnowledgeCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KnowledgeCell.m; sourceTree = "<group>"; };
E52A75661B60913A00090038 /* KnowledgeViewModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = KnowledgeViewModel.h; sourceTree = "<group>"; };
E52A75671B60913A00090038 /* KnowledgeViewModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = KnowledgeViewModel.m; sourceTree = "<group>"; };
E556A7C31B55F89A007CFCF5 /* DeepBreathing.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DeepBreathing.app; sourceTree = BUILT_PRODUCTS_DIR; };
E556A7C71B55F89A007CFCF5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
E556A7C81B55F89A007CFCF5 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -552,6 +565,8 @@
E5D5F9F61B5F619400D73C0B /* 急性发作.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "急性发作.png"; sourceTree = "<group>"; };
E5D5F9F71B5F619400D73C0B /* 错.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "错.png"; sourceTree = "<group>"; };
E5D5F9F81B5F619400D73C0B /* 错_选中.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "错_选中.png"; sourceTree = "<group>"; };
E5D5FA091B5F6D5500D73C0B /* QuestionBaseView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = QuestionBaseView.h; sourceTree = "<group>"; };
E5D5FA0A1B5F6D5500D73C0B /* QuestionBaseView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = QuestionBaseView.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -870,6 +885,12 @@
children = (
E58A53E61B57520C00E5413D /* KnowledgeViewController.h */,
E58A53E71B57520C00E5413D /* KnowledgeViewController.m */,
E52A75631B6087B600090038 /* KnowledgeCell.h */,
E52A75641B6087B600090038 /* KnowledgeCell.m */,
E52A75601B60822500090038 /* KnowledgeModel.h */,
E52A75611B60822500090038 /* KnowledgeModel.m */,
E52A75661B60913A00090038 /* KnowledgeViewModel.h */,
E52A75671B60913A00090038 /* KnowledgeViewModel.m */,
);
path = "知识";
sourceTree = "<group>";
Expand Down Expand Up @@ -899,6 +920,8 @@
E58A52321B5745B300E5413D /* HomePageViewController.m */,
E5D5F9E11B5F3EB200D73C0B /* HomePageQuestionManager.h */,
E5D5F9E21B5F3EB200D73C0B /* HomePageQuestionManager.m */,
E5D5FA091B5F6D5500D73C0B /* QuestionBaseView.h */,
E5D5FA0A1B5F6D5500D73C0B /* QuestionBaseView.m */,
);
path = "首页";
sourceTree = "<group>";
Expand Down Expand Up @@ -1335,6 +1358,8 @@
E58A546A1B58971600E5413D /* NetworkingManager.m */,
E58A546C1B5897A400E5413D /* NetworkingManager+Login.h */,
E58A546D1B5897A400E5413D /* NetworkingManager+Login.m */,
E52A755D1B6078DE00090038 /* NetworkingManager+Knowledge.h */,
E52A755E1B6078DE00090038 /* NetworkingManager+Knowledge.m */,
);
path = NetworkingManager;
sourceTree = "<group>";
Expand Down Expand Up @@ -1663,12 +1688,14 @@
E58A52361B57472500E5413D /* UserModel.m in Sources */,
E58A54551B57A44200E5413D /* AFURLConnectionOperation.m in Sources */,
E58A52A11B574B3800E5413D /* DHVector.m in Sources */,
E52A75621B60822500090038 /* KnowledgeModel.m in Sources */,
E58A52B71B574B3800E5413D /* DHDrawerViewController.m in Sources */,
E50905991B5C9551000FB9FE /* DHScanScrollView.m in Sources */,
E58A53EE1B57527400E5413D /* AssessmentViewController.m in Sources */,
E509058B1B5C9551000FB9FE /* DHImageTextButton.m in Sources */,
E58A54721B58ABCC00E5413D /* RegisterViewController.m in Sources */,
E50905921B5C9551000FB9FE /* DHGradientStepProgressView.m in Sources */,
E52A75681B60913A00090038 /* KnowledgeViewModel.m in Sources */,
E58A545B1B57A44200E5413D /* UIAlertView+AFNetworking.m in Sources */,
E509058A1B5C9551000FB9FE /* DHButton.m in Sources */,
E58A54601B57A44200E5413D /* UIWebView+AFNetworking.m in Sources */,
Expand Down Expand Up @@ -1696,6 +1723,7 @@
E556A7CC1B55F89A007CFCF5 /* AppDelegate.m in Sources */,
E556A7C91B55F89A007CFCF5 /* main.m in Sources */,
E50905901B5C9551000FB9FE /* CABasicAnimation+AnimationCompletionBlock.m in Sources */,
E52A755F1B6078DE00090038 /* NetworkingManager+Knowledge.m in Sources */,
E509058E1B5C9551000FB9FE /* DHInfoFillInView.m in Sources */,
E58A546E1B5897A400E5413D /* NetworkingManager+Login.m in Sources */,
E58A52A01B574B3800E5413D /* DHSystemAppNavigationTransition.m in Sources */,
Expand All @@ -1709,11 +1737,13 @@
E50905931B5C9551000FB9FE /* DHNormalProgressView.m in Sources */,
E58A529F1B574B3800E5413D /* DHPerspectiveTransition.m in Sources */,
E509058F1B5C9551000FB9FE /* DHInfoPresentationView.m in Sources */,
E52A75651B6087B600090038 /* KnowledgeCell.m in Sources */,
E58A54591B57A44200E5413D /* AFNetworkActivityIndicatorManager.m in Sources */,
E58A53EB1B57523D00E5413D /* MedicineViewController.m in Sources */,
E58A529A1B574B3800E5413D /* DHRequest.m in Sources */,
E58A53F21B5756D500E5413D /* LeftViewController.m in Sources */,
E58A54561B57A44200E5413D /* AFURLRequestSerialization.m in Sources */,
E5D5FA0B1B5F6D5500D73C0B /* QuestionBaseView.m in Sources */,
E58A52981B574B3800E5413D /* DHConvenienceAutoLayout.m in Sources */,
E58A54521B57A44200E5413D /* AFHTTPSessionManager.m in Sources */,
E50905941B5C9551000FB9FE /* DHProgressAnimation.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,37 @@
stopOnStyle = "0">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "Yes"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "DeepBreathing/AppDelegate.m"
timestampString = "459309962.620302"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "116"
endingLineNumber = "116"
landmarkName = "-application:didRegisterForRemoteNotificationsWithDeviceToken:"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "DeepBreathing/&#x6a21;&#x5757;/&#x77e5;&#x8bc6;/KnowledgeModel.m"
timestampString = "459312512.38688"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "16"
endingLineNumber = "16"
landmarkName = "-getKnowledgeDataList"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
16 changes: 6 additions & 10 deletions DeepBreathing/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,12 @@ @interface AppDelegate ()
@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
#if TARGET_IPHONE_SIMULATOR

NSArray * array = @[@"李波",@"吕玉梅",@"蒲嘉欣",@"李玉辉",@"刘英群",@"肖文",@"刘艺前",@"李晓强",@"王振宇",@"唐德刚",@"唐明斌",@"罗野",@"肖攀",@"牛冠",@"陈立",@"陈伟",@"陈超",@"杜毅"];
NSInteger index = arc4random()%array.count;

NSLog(@"%@",array[index]);


[UserModel defaultUser].token = @"111111111";

#if TARGET_IPHONE_SIMULATOR
[UserModel defaultUser].token = @"";
[[NSUserDefaults standardUserDefaults] setObject:[UserModel defaultUser].token forKey:@"DeviceToken"];
[[NSUserDefaults standardUserDefaults] synchronize];

#else
if (([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)) {
Expand All @@ -43,8 +39,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeSound | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeBadge)];
}
#endif

[UserModel defaultUser].token = [[NSUserDefaults standardUserDefaults] objectForKey:@"DeviceToken"];
NSString * token = [[NSUserDefaults standardUserDefaults] objectForKey:@"DeviceToken"];
[UserModel defaultUser].token = token;

if ([[NSUserDefaults standardUserDefaults] objectForKey:kUserIdKey]) {

Expand Down
2 changes: 2 additions & 0 deletions DeepBreathing/PrefixHeader.pch
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifndef DeepBreathing_PrefixHeader_pch
#define DeepBreathing_PrefixHeader_pch

#define BASE_URL @"http://db.rimionline.com/"

#define IMAGE_WITH_NAME(name) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForAuxiliaryExecutable:name]]

#define RGB_COLOR(r,g,b) [UIColor colorWithRed:r/255.f green:g/255.f blue:b/255.f alpha:1]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// NetworkingManager+Knowledge.h
// DeepBreathing
//
// Created by DreamHack on 15-7-23.
// Copyright (c) 2015年 DreamHack. All rights reserved.
//

#import "NetworkingManager.h"

@interface NetworkingManager (Knowledge)

+ (AFHTTPRequestOperation *)getKnowledgeWithParams:(NSDictionary *)params success:(SuccessBlock)success failure:(FailureBlock)failure;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// NetworkingManager+Knowledge.m
// DeepBreathing
//
// Created by DreamHack on 15-7-23.
// Copyright (c) 2015年 DreamHack. All rights reserved.
//

#import "NetworkingManager+Knowledge.h"

@implementation NetworkingManager (Knowledge)

+ (AFHTTPRequestOperation *)getKnowledgeWithParams:(NSDictionary *)params success:(SuccessBlock)success failure:(FailureBlock)failure
{
AFHTTPRequestOperation * operation = [NetworkingManager postWithUrl:@"app/knowledge/getKnowList.html" requestParams:params successHandler:^(id responseObj) {
if (success) {
success(responseObj);
}
} failureHandler:^(NSError *error) {
if (failure) {
failure(error);
}
}];

return operation;
}

@end
2 changes: 1 addition & 1 deletion DeepBreathing/Tools/NetworkingManager/NetworkingManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import "NetworkingManager.h"
#import "AFNetworking.h"

#define BASE_URL @"http://db.rimionline.com/"


@implementation NetworkingManager

Expand Down
1 change: 1 addition & 0 deletions DeepBreathing/模块/UserModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
@property (nonatomic, strong) NSString * sex;
@property (nonatomic, strong) NSString * photo;
@property (nonatomic, strong) NSString * token;
@property (nonatomic, strong) NSString * password;


+ (UserModel *)defaultUser;
Expand Down
8 changes: 6 additions & 2 deletions DeepBreathing/模块/UserModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ @implementation UserModel

+ (UserModel *)defaultUser
{

return nil;
static UserModel * userModel;
static dispatch_once_t once;
dispatch_once(&once, ^{
userModel = [[UserModel alloc] init];
});
return userModel;
}

@end
70 changes: 44 additions & 26 deletions DeepBreathing/模块/登录/LoginViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#import "MainTabViewController.h"
#import "DHDrawerViewController.h"
#import "LeftViewController.h"
#import "NetworkingManager+Login.h"

@interface LoginViewController ()

Expand Down Expand Up @@ -113,32 +114,17 @@ - (UITextField *)passwordField

- (void)onLogin:(UIButton *)sender
{
// 各个模块controller的类名
NSArray * controllerClassNames = @[@"HomePageViewController",@"AssessmentViewController",@"MedicineViewController",@"KnowledgeViewController",@"AttendanceViewController"];

// 传给tabController的controller数组
NSMutableArray * controllerArray = [NSMutableArray arrayWithCapacity:0];

for (NSString * className in controllerClassNames) {
// 通过类名初始化controller
UIViewController * controller = [[NSClassFromString(className) alloc] init];
[controllerArray addObject:controller];
[NetworkingManager loginWithUserName:_usernameField.text password:_passwordField.text successHandler:^(id responseObj) {

}


// 初始化tabController
MainTabViewController * mainViewController = [[MainTabViewController alloc] initWithViewControllers:controllerArray];


// 初始化抽屉controller
// 因为某一个子controller push的效果是把整个tabController进行push,所以要把tabController作为一个navigationController的rootController
UINavigationController * naVC = [[UINavigationController alloc] initWithRootViewController:mainViewController];
naVC.navigationBar.hidden = YES;

DHDrawerViewController * drawerViewController = [[DHDrawerViewController alloc] initWithMainViewContorller:naVC leftViewController:[[LeftViewController alloc] init] rightViewController:nil];

[self.navigationController presentViewController:drawerViewController animated:YES completion:nil];


[UserModel defaultUser].phoneNumber = _usernameField.text;
[UserModel defaultUser].password = _passwordField.text;

[self presentToMainViewController];
} failureHandler:^(NSError *error) {

}];
}

- (void)onRegister:(UIButton *)sender
Expand Down Expand Up @@ -193,8 +179,40 @@ - (UIButton *)buttonWithFrame:(CGRect)frame title:(NSString *)title action:(SEL)
}


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.view endEditing:YES];
}

- (void)presentToMainViewController
{
// 各个模块controller的类名
NSArray * controllerClassNames = @[@"HomePageViewController",@"AssessmentViewController",@"MedicineViewController",@"KnowledgeViewController",@"AttendanceViewController"];

// 传给tabController的controller数组
NSMutableArray * controllerArray = [NSMutableArray arrayWithCapacity:0];

for (NSString * className in controllerClassNames) {
// 通过类名初始化controller
UIViewController * controller = [[NSClassFromString(className) alloc] init];
[controllerArray addObject:controller];

}


// 初始化tabController
MainTabViewController * mainViewController = [[MainTabViewController alloc] initWithViewControllers:controllerArray];


// 初始化抽屉controller
// 因为某一个子controller push的效果是把整个tabController进行push,所以要把tabController作为一个navigationController的rootController
UINavigationController * naVC = [[UINavigationController alloc] initWithRootViewController:mainViewController];
naVC.navigationBar.hidden = YES;

DHDrawerViewController * drawerViewController = [[DHDrawerViewController alloc] initWithMainViewContorller:naVC leftViewController:[[LeftViewController alloc] init] rightViewController:nil];

[self.navigationController presentViewController:drawerViewController animated:YES completion:nil];


}

@end
24 changes: 24 additions & 0 deletions DeepBreathing/模块/知识/KnowledgeCell.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// KnowledgeCell.h
// DeepBreathing
//
// Created by DreamHack on 15-7-23.
// Copyright (c) 2015年 DreamHack. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface KnowledgeCell : UITableViewCell

@property (nonatomic, strong) NSDictionary * cellInfo;

@end

extern NSString * const kKnowledgeCellInfoImageKey;

extern NSString * const kKnowledgeCellInfoTitleKey;

extern NSString * const kKnowledgeCellInfoDateKey;



Loading

0 comments on commit ebf04c8

Please sign in to comment.