Skip to content

Commit

Permalink
dev:完成修改昵称和显示昵称的功能,下面需要封装界面跳转的代码
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyufeng1991 committed Nov 17, 2015
1 parent a99d249 commit 580ffc2
Show file tree
Hide file tree
Showing 11 changed files with 245 additions and 24 deletions.
6 changes: 6 additions & 0 deletions Oncenote.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
719AF3A91BFA308F009D602D /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 719AF3A81BFA308F009D602D /* Foundation.framework */; };
719AF3BA1BFB0440009D602D /* SettingViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 719AF3B91BFB0440009D602D /* SettingViewController.m */; settings = {ASSET_TAGS = (); }; };
719AF3BD1BFB10CD009D602D /* SettingList.m in Sources */ = {isa = PBXBuildFile; fileRef = 719AF3BC1BFB10CD009D602D /* SettingList.m */; settings = {ASSET_TAGS = (); }; };
719AF3C01BFB18DE009D602D /* NicknameViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 719AF3BF1BFB18DE009D602D /* NicknameViewController.m */; settings = {ASSET_TAGS = (); }; };
71A793751BF5B5F000410FFC /* LoginViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 71A793741BF5B5F000410FFC /* LoginViewController.m */; settings = {ASSET_TAGS = (); }; };
71A793781BF5CDCA00410FFC /* RegisterViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 71A793771BF5CDCA00410FFC /* RegisterViewController.m */; settings = {ASSET_TAGS = (); }; };
71A7937C1BF5E75600410FFC /* BmobOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = 71A7937B1BF5E75600410FFC /* BmobOperation.m */; settings = {ASSET_TAGS = (); }; };
Expand Down Expand Up @@ -161,6 +162,8 @@
719AF3B91BFB0440009D602D /* SettingViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SettingViewController.m; sourceTree = "<group>"; };
719AF3BB1BFB10CD009D602D /* SettingList.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SettingList.h; sourceTree = "<group>"; };
719AF3BC1BFB10CD009D602D /* SettingList.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SettingList.m; sourceTree = "<group>"; };
719AF3BE1BFB18DE009D602D /* NicknameViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NicknameViewController.h; sourceTree = "<group>"; };
719AF3BF1BFB18DE009D602D /* NicknameViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NicknameViewController.m; sourceTree = "<group>"; };
71A793731BF5B5F000410FFC /* LoginViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LoginViewController.h; sourceTree = "<group>"; };
71A793741BF5B5F000410FFC /* LoginViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LoginViewController.m; sourceTree = "<group>"; };
71A793761BF5CDCA00410FFC /* RegisterViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RegisterViewController.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -397,6 +400,8 @@
71BEC2861BF8485D0003F173 /* AllNoteDetailViewController.m */,
719AF3B81BFB0440009D602D /* SettingViewController.h */,
719AF3B91BFB0440009D602D /* SettingViewController.m */,
719AF3BE1BFB18DE009D602D /* NicknameViewController.h */,
719AF3BF1BFB18DE009D602D /* NicknameViewController.m */,
);
name = ViewController;
sourceTree = "<group>";
Expand Down Expand Up @@ -708,6 +713,7 @@
71BEC2871BF8485D0003F173 /* AllNoteDetailViewController.m in Sources */,
717902EA1BF48FC100428756 /* main.m in Sources */,
71BEC28A1BF8BC100003F173 /* LaunchScreenViewController.m in Sources */,
719AF3C01BFB18DE009D602D /* NicknameViewController.m in Sources */,
718FF3A71BF63687009A3F6D /* Constant.m in Sources */,
71BEC28E1BF8C7830003F173 /* AllUtils.m in Sources */,
719AF3BA1BFB0440009D602D /* SettingViewController.m in Sources */,
Expand Down
3 changes: 2 additions & 1 deletion Oncenote/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
@property (strong, nonatomic) UIWindow *window;

@property (strong,nonatomic) NSString *GLOBAL_USERID;//全局的objectID;当前的用户ID;
@property (strong,nonatomic) NSString *GLOBAL_USERNAME;//全局的用户名;
@property (strong,nonatomic) NSString *GLOBAL_USERNAME;//全局的用户名,也就是手机号;
@property (strong,nonatomic) NSString *GLOBAL_NICKNAME;//全局的昵称;

//尝试全局使用一个笔记数组;

Expand Down
69 changes: 65 additions & 4 deletions Oncenote/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -304,20 +304,81 @@
</objects>
<point key="canvasLocation" x="1760" y="878"/>
</scene>
<!--View Controller-->
<!--Nickname View Controller-->
<scene sceneID="T6s-sg-zZ9">
<objects>
<viewController id="xNu-qL-Wmw" sceneMemberID="viewController">
<viewController storyboardIdentifier="NicknameViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="xNu-qL-Wmw" customClass="NicknameViewController" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="f5k-cb-kB7">
<rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<view contentMode="scaleToFill" id="hHG-s8-xQS">
<rect key="frame" x="0.0" y="0.0" width="320" height="65"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<subviews>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="rEx-Kb-jUe">
<rect key="frame" x="13" y="25" width="40" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<animations/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<state key="normal" title="取消">
<color key="titleColor" red="0.0" green="0.52941176469999995" blue="0.25882352939999997" alpha="1" colorSpace="calibratedRGB"/>
</state>
<connections>
<action selector="naviCancelButtonPressed:" destination="xNu-qL-Wmw" eventType="touchUpInside" id="VNN-hk-S6A"/>
</connections>
</button>
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="修改昵称" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="lYI-6D-S1q">
<rect key="frame" x="120" y="29" width="80" height="24"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<animations/>
<fontDescription key="fontDescription" type="system" pointSize="20"/>
<color key="textColor" cocoaTouchSystemColor="darkTextColor"/>
<nil key="highlightedColor"/>
</label>
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="WMV-95-Eaw">
<rect key="frame" x="264" y="25" width="32" height="32"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<animations/>
<fontDescription key="fontDescription" type="system" pointSize="16"/>
<state key="normal" title="完成">
<color key="titleColor" red="0.0" green="0.52941176469999995" blue="0.25882352939999997" alpha="1" colorSpace="calibratedRGB"/>
</state>
<connections>
<action selector="naviDoneButtonPressed:" destination="xNu-qL-Wmw" eventType="touchUpInside" id="IU4-O6-d4O"/>
<action selector="naviLogoutButtonPressed:" destination="uPh-2i-OcR" eventType="touchUpInside" id="BfC-2O-ItQ"/>
<action selector="naviStoreButtonPressed:" destination="TeH-OH-vUw" eventType="touchUpInside" id="2Rh-ZQ-a7a"/>
</connections>
</button>
</subviews>
<animations/>
<color key="backgroundColor" red="0.93725490199999995" green="0.93725490199999995" blue="0.95686274510000002" alpha="1" colorSpace="calibratedRGB"/>
</view>
<view contentMode="scaleToFill" id="3Yr-Y1-PLf">
<rect key="frame" x="-294" y="65" width="1000" height="1"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<animations/>
<color key="backgroundColor" red="0.89019607840000003" green="0.89019607840000003" blue="0.89019607840000003" alpha="1" colorSpace="calibratedRGB"/>
</view>
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="输入你的昵称" textAlignment="natural" minimumFontSize="17" clearButtonMode="whileEditing" id="A2m-Iy-sUK">
<rect key="frame" x="20" y="88" width="280" height="40"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
<animations/>
<color key="backgroundColor" red="0.38823529410000002" green="0.76078431369999999" blue="0.47843137250000001" alpha="0.80133551520000001" colorSpace="calibratedRGB"/>
<fontDescription key="fontDescription" type="system" pointSize="14"/>
<textInputTraits key="textInputTraits" autocorrectionType="no" spellCheckingType="no"/>
</textField>
</subviews>
<animations/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<color key="backgroundColor" red="0.27058823529411763" green="0.69019607843137254" blue="0.38039215686274508" alpha="1" colorSpace="calibratedRGB"/>
</view>
<connections>
<outlet property="nicknameTextField" destination="A2m-Iy-sUK" id="pei-K2-hcn"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="GWe-cX-3yl" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="2284" y="878"/>
<point key="canvasLocation" x="2271" y="878"/>
</scene>
<!--Note Detail View Controller-->
<scene sceneID="5o2-xh-LTC">
Expand Down
2 changes: 2 additions & 0 deletions Oncenote/BmobOperation.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@


+ (void)deleteNoteFromDatabase:(NSString*)tableName noteId:(NSString*)noteId;

+ (void)updateNicknameToUserTable:(NSString*)tableName userId:(NSString*)userId nickname:(NSString*)nickname;
@end
17 changes: 17 additions & 0 deletions Oncenote/BmobOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ + (void)deleteNoteFromDatabase:(NSString*)tableName noteId:(NSString*)noteId{
}];
}

#pragma mark - 修改用户的昵称
+ (void)updateNicknameToUserTable:(NSString*)tableName userId:(NSString*)userId nickname:(NSString*)nickname{

BmobQuery *update = [BmobQuery queryWithClassName:tableName];
[update getObjectInBackgroundWithId:userId block:^(BmobObject *object,NSError *error){
if (!error) {
if (object) {
[object setObject:nickname forKey:@"nickname"];

[object updateInBackground];
}
}else{
//进行错误处理
}
}];
}



@end
1 change: 1 addition & 0 deletions Oncenote/LaunchScreenViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ - (void)viewDidAppear:(BOOL)animated{
AppDelegate *globalApp = [[UIApplication sharedApplication] delegate];
globalApp.GLOBAL_USERNAME = [userDefaults objectForKey:@"username"];
globalApp.GLOBAL_USERID = [userDefaults objectForKey:@"userId"];
globalApp.GLOBAL_NICKNAME = [userDefaults objectForKey:@"nickname"];


UIViewController *mainViewController = [[UIViewController alloc] init];
Expand Down
48 changes: 37 additions & 11 deletions Oncenote/LoginViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,26 @@
#import <BmobSDK/Bmob.h>
#import "AppDelegate.h"
#import "AllUtils.h"
#import "Constant.h"

@interface LoginViewController ()

@property (weak, nonatomic) IBOutlet UITextField *usernameTextField;
@property (weak, nonatomic) IBOutlet UITextField *passwordTextField;

@property(nonatomic,strong) AppDelegate *globalApp;
@property(nonatomic,strong) NSUserDefaults *userDefaults;

@end

@implementation LoginViewController

- (void)viewDidLoad {
[super viewDidLoad];

self.globalApp = [[UIApplication sharedApplication] delegate];
self.userDefaults = [NSUserDefaults standardUserDefaults];

}

#pragma mark - 所有的按钮点击;
Expand All @@ -38,24 +45,43 @@ - (IBAction)loginButtonPressed:(id)sender {
[AllUtils showPromptDialog:@"提示" andMessage:@"登录失败,请输入正确的手机号和密码" OKButton:@"确定" OKButtonAction:nil cancelButton:@"" cancelButtonAction:nil contextViewController:self];

}else{
//登录成功要进行一次查询,查询出该用户的nickname;

BmobQuery *queryNickname = [BmobQuery queryWithClassName:USER_TABLE];
[queryNickname getObjectInBackgroundWithId:user.objectId block:^(BmobObject *object, NSError *error) {
if (error) {
//错误处理;
}else{

if (object) {
NSString *nickname = [object objectForKey:@"nickname"];
NSLog(@"1111111111昵称是:%@",nickname);

[self.userDefaults setObject:nickname forKey:@"nickname"];
self.globalApp.GLOBAL_NICKNAME = nickname;




//界面跳转;
UIViewController *mainViewController = [[UIViewController alloc] init];
mainViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"MainViewController"];
[self presentViewController:mainViewController animated:true completion:nil];
}
}
}];

//给全局变量设值;
AppDelegate *globalApp = [[UIApplication sharedApplication] delegate];
globalApp.GLOBAL_USERNAME = username;
globalApp.GLOBAL_USERID = user.objectId;
self.globalApp.GLOBAL_USERNAME = username;
self.globalApp.GLOBAL_USERID = user.objectId;


//登录成功,同时把用户名密码存储到UserDefault中;
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:user.objectId forKey:@"userId"];
[userDefaults setObject:username forKey:@"username"];
[userDefaults setObject:password forKey:@"password"];
[self.userDefaults setObject:user.objectId forKey:@"userId"];
[self.userDefaults setObject:username forKey:@"username"];
[self.userDefaults setObject:password forKey:@"password"];


// NSLog(@"登录成功,username:%@,password:%@,userId:%@",user.username,user.password,user.objectId);
UIViewController *mainViewController = [[UIViewController alloc] init];
mainViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"MainViewController"];
[self presentViewController:mainViewController animated:true completion:nil];

}
}];
Expand Down
9 changes: 8 additions & 1 deletion Oncenote/MainViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,14 @@ - (void)viewDidLoad {

//设置navi中的用户名;
AppDelegate *app = [[UIApplication sharedApplication] delegate];
self.naviUsername.text = app.GLOBAL_USERNAME;

NSLog(@"22222222222222用户的昵称是:%@",app.GLOBAL_NICKNAME);

if (app.GLOBAL_NICKNAME == nil || [app.GLOBAL_NICKNAME isEqualToString:@""]) {
self.naviUsername.text = app.GLOBAL_USERNAME;
} else {
self.naviUsername.text = app.GLOBAL_NICKNAME;
}

//绑定控件;
[self.naviSettingImage addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(naviSettingButtonPressed:)]];
Expand Down
13 changes: 13 additions & 0 deletions Oncenote/NicknameViewController.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// NicknameViewController.h
// Oncenote
//
// Created by chenyufeng on 15/11/17.
// Copyright © 2015年 chenyufengweb. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface NicknameViewController : UIViewController

@end
75 changes: 75 additions & 0 deletions Oncenote/NicknameViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//
// NicknameViewController.m
// Oncenote
//
// Created by chenyufeng on 15/11/17.
// Copyright © 2015年 chenyufengweb. All rights reserved.
//

#import "NicknameViewController.h"
#import "SettingViewController.h"
#import "BmobOperation.h"
#import "Constant.h"
#import "AppDelegate.h"
#import "AllUtils.h"

@interface NicknameViewController ()



@property (weak, nonatomic) IBOutlet UITextField *nicknameTextField;




@end

@implementation NicknameViewController

- (void)viewDidLoad {
[super viewDidLoad];

AppDelegate *app = [[UIApplication sharedApplication] delegate];

if (app.GLOBAL_NICKNAME == nil || [app.GLOBAL_NICKNAME isEqualToString:@""]) {
self.nicknameTextField.text = @"";
}else{
self.nicknameTextField.text = app.GLOBAL_NICKNAME;
}


}

- (IBAction)naviCancelButtonPressed:(id)sender {

UIViewController *settingViewController = [[UIViewController alloc] init];
settingViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SettingViewController"];
[self presentViewController:settingViewController animated:true completion:nil];

}

- (IBAction)naviDoneButtonPressed:(id)sender {

AppDelegate *app = [[UIApplication sharedApplication] delegate];
app.GLOBAL_NICKNAME = self.nicknameTextField.text;

//同时也要把这个昵称存到NSUSerDefaults;
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:self.nicknameTextField.text forKey:@"nickname"];

//把昵称插入到指定UserID的数据库中;
[BmobOperation updateNicknameToUserTable:USER_TABLE userId:app.GLOBAL_USERID nickname:self.nicknameTextField.text];


[AllUtils showPromptDialog:@"提示" andMessage:@"修改昵称成功" OKButton:@"确定" OKButtonAction:^(UIAlertAction *action) {
UIViewController *settingViewController = [[UIViewController alloc] init];
settingViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SettingViewController"];
[self presentViewController:settingViewController animated:true completion:nil];

} cancelButton:@"" cancelButtonAction:nil contextViewController:self];

}



@end
Loading

0 comments on commit 580ffc2

Please sign in to comment.