From 968115e8fcfc6787bb4203022ed9535393e54f27 Mon Sep 17 00:00:00 2001 From: KAWASHIMA Yoshiyuki Date: Sun, 28 Nov 2021 09:37:01 +0900 Subject: [PATCH 1/2] =?UTF-8?q?name=20=E3=82=92=E5=85=A5=E5=8A=9B=E3=81=A7?= =?UTF-8?q?=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Static Cells を利用する - 不特定な要素を扱わないので、利用用途が限定されているため Static で良い - TextField を扱いやすくなる - NavigationController を追加 - ライフサイクルの管理を楽にするため - viewWillAppear で更新処理ができるようになる fixes #8 #27 --- .../Base.lproj/Main.storyboard | 202 ++++++++++++------ OneTimePasswordExample/SettingController.m | 68 +++--- OneTimePasswordExample/ViewController.m | 15 +- 3 files changed, 180 insertions(+), 105 deletions(-) diff --git a/OneTimePasswordExample/Base.lproj/Main.storyboard b/OneTimePasswordExample/Base.lproj/Main.storyboard index 32dd920..25f764f 100644 --- a/OneTimePasswordExample/Base.lproj/Main.storyboard +++ b/OneTimePasswordExample/Base.lproj/Main.storyboard @@ -1,9 +1,9 @@ - + - + @@ -35,7 +35,7 @@ - + @@ -64,75 +64,155 @@ - + - - + + - + - - - - - - - - - - - + + + + + + + + + + + - - + + + + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/OneTimePasswordExample/SettingController.m b/OneTimePasswordExample/SettingController.m index 8ad0cb8..0d9efe9 100644 --- a/OneTimePasswordExample/SettingController.m +++ b/OneTimePasswordExample/SettingController.m @@ -6,7 +6,6 @@ // #import "SettingController.h" -#import "SettingsTableViewCell.h" #import "OneTimePasswordSettings.h" #pragma mark - Settings item @@ -19,10 +18,14 @@ typedef NS_ENUM(UInt8, SettingsItem) { extern SettingsItem SettingsItemUnknown; - #pragma mark - Settings table view controller -@interface SettingController () +@interface SettingController () + +@property (weak, nonatomic) IBOutlet UITextField *nameTextField; +@property (weak, nonatomic) IBOutlet UILabel *algorithmLabel; +@property (weak, nonatomic) IBOutlet UILabel *digitsLabel; +@property (weak, nonatomic) IBOutlet UILabel *periodLabel; @property (nonatomic) OneTimePasswordSettings *settings; @@ -45,6 +48,12 @@ - (void)viewDidLoad { self.settings = [OneTimePasswordSettings sharedInstance]; + self.nameTextField.delegate = self; + self.nameTextField.text = self.settings.name; + self.algorithmLabel.text = [self.settings algorithmString]; + self.digitsLabel.text = [self.settings digitsString]; + self.periodLabel.text = [self.settings periodString]; + self.pickerView = [[UIPickerView alloc] init]; self.pickerView.center = self.view.center; self.pickerView.dataSource = self; @@ -56,47 +65,28 @@ - (void)viewDidLoad { self.periodPatterns = @[@"30", @"60"]; } -#pragma mark - Table view data source - -- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { - return 1; -} - -- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { - return 3; -} - -- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { - SettingsTableViewCell *cell = (SettingsTableViewCell *)[tableView dequeueReusableCellWithIdentifier: @"SettingsTableViewCell" forIndexPath:indexPath]; - - switch (indexPath.row) { - case 0: - cell.titleLabel.text = @"アルゴリズム"; - cell.valueLabel.text = [self.settings algorithmString]; - break; - case 1: - cell.titleLabel.text = @"OTP桁数"; - cell.valueLabel.text = [self.settings digitsString]; - break; - case 2: - cell.titleLabel.text = @"タイムステップ数"; - cell.valueLabel.text = [self.settings periodString]; - break; - } - - return cell; -} - #pragma mark - Table view delegate - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { // FIXME: タップしても反応しないことがある - self.settingsItem = indexPath.row; + self.settingsItem = (indexPath.row - 1); NSInteger selectRow = [self pickerSelectRowWithItem:self.settingsItem]; [self.pickerView selectRow:selectRow inComponent:0 animated:true]; [self.pickerView reloadAllComponents]; } +#pragma mark - Text field delegate + +- (void)textFieldDidEndEditing:(UITextField *)textField { + self.settings.name = textField.text; +} + +- (BOOL)textFieldShouldReturn:(UITextField *)textField { + [textField resignFirstResponder]; + self.settings.name = textField.text; + return YES; +} + #pragma mark - Picker view data source - (NSInteger)numberOfComponentsInPickerView:(nonnull UIPickerView *)pickerView { @@ -111,8 +101,6 @@ - (NSInteger)pickerView:(nonnull UIPickerView *)pickerView numberOfRowsInCompone return self.digitsPatterns.count; case PeriodItem: return self.periodPatterns.count; - default: - return 0; } } @@ -127,20 +115,21 @@ - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row f case PeriodItem: return self.periodPatterns[row]; } - - return @""; } - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { switch (self.settingsItem) { case AlgorithmItem: [self.settings saveAlgorithmString:self.algorithmPatterns[row]]; + self.algorithmLabel.text = [self.settings algorithmString]; break; case DigitsItem: [self.settings saveDigitsString:self.digitsPatterns[row]]; + self.digitsLabel.text = [self.settings digitsString]; break; case PeriodItem: [self.settings savePeriodString:self.periodPatterns[row]]; + self.periodLabel.text = [self.settings periodString]; break; } @@ -158,7 +147,6 @@ - (NSInteger)pickerSelectRowWithItem:(SettingsItem)item{ case PeriodItem: return [self indexWithPeriodString:[self.settings periodString]]; } - return 0; } - (NSInteger)indexWithAlgorithmString:(NSString *)algorithmString { diff --git a/OneTimePasswordExample/ViewController.m b/OneTimePasswordExample/ViewController.m index 2e1fe88..f89e3d1 100644 --- a/OneTimePasswordExample/ViewController.m +++ b/OneTimePasswordExample/ViewController.m @@ -16,19 +16,26 @@ @interface ViewController () @property (weak, nonatomic) IBOutlet UILabel *oneTimePasswordLabel; @property (weak, nonatomic) IBOutlet UAProgressView *oneTimePasswordProgressView; + +@property (nonatomic) NSTimer * timer; @property (nonatomic, assign) CGFloat localProgress; @end @implementation ViewController - -- (void)viewDidLoad { - [super viewDidLoad]; +- (void)viewWillAppear:(BOOL)animated { + [super viewWillAppear:animated]; [self initOneTimePasswordView]; } +- (void)viewDidDisappear:(BOOL)animated { + [super viewDidDisappear:animated]; + + [self.timer invalidate]; +} + - (void)initOneTimePasswordView { self.settings = [OneTimePasswordSettings sharedInstance]; @@ -43,7 +50,7 @@ - (void)initOneTimePasswordView { [self.oneTimePasswordLabel setText:password]; NSTimeInterval timeInterval = self.settings.period / 1000; - [NSTimer scheduledTimerWithTimeInterval:timeInterval target:self selector:@selector(updateOneTimePasswordView:) userInfo:nil repeats:YES]; + self.timer = [NSTimer scheduledTimerWithTimeInterval:timeInterval target:self selector:@selector(updateOneTimePasswordView:) userInfo:nil repeats:YES]; } - (void)updateOneTimePasswordView:(NSTimer *)timer { From 2d1ae9a0e23f48af94f919bcab52fbc6347ba596 Mon Sep 17 00:00:00 2001 From: KAWASHIMA Yoshiyuki Date: Sun, 28 Nov 2021 09:55:12 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E4=B8=8D=E8=A6=81=E3=81=AB=E3=81=AA?= =?UTF-8?q?=E3=81=A3=E3=81=9F=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92?= =?UTF-8?q?=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes #14 --- .../project.pbxproj | 10 ---- .../SettingTableViewCell.storyboard | 30 ----------- .../SettingTableViewCell.xib | 51 ------------------- .../SettingsTableViewCell.h | 19 ------- .../SettingsTableViewCell.m | 23 --------- 5 files changed, 133 deletions(-) delete mode 100644 OneTimePasswordExample/SettingTableViewCell.storyboard delete mode 100644 OneTimePasswordExample/SettingTableViewCell.xib delete mode 100644 OneTimePasswordExample/SettingsTableViewCell.h delete mode 100644 OneTimePasswordExample/SettingsTableViewCell.m diff --git a/OneTimePasswordExample.xcodeproj/project.pbxproj b/OneTimePasswordExample.xcodeproj/project.pbxproj index 5a35b1b..f93a72c 100644 --- a/OneTimePasswordExample.xcodeproj/project.pbxproj +++ b/OneTimePasswordExample.xcodeproj/project.pbxproj @@ -19,8 +19,6 @@ 08C8E27B26BBA377006D4608 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 08C8E27926BBA377006D4608 /* LaunchScreen.storyboard */; }; 08C8E27E26BBA377006D4608 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 08C8E27D26BBA377006D4608 /* main.m */; }; 4F8B41252703520D00CF6A1A /* SettingController.m in Sources */ = {isa = PBXBuildFile; fileRef = 4F8B41242703520D00CF6A1A /* SettingController.m */; }; - 4F8B41292705F8CF00CF6A1A /* SettingsTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 4F8B41282705F8CF00CF6A1A /* SettingsTableViewCell.m */; }; - 4F8B412D2709A50E00CF6A1A /* SettingTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 4F8B412C2709A50E00CF6A1A /* SettingTableViewCell.xib */; }; 9A376FD397E03D93D3D80530 /* libPods-OneTimePasswordExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C08B5529218DAFE111F19B53 /* libPods-OneTimePasswordExample.a */; }; E9FD60875365F5896E9C3D94 /* libPods-OneTimePasswordExampleTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = BC7DC5E5BD3FFB6BD8F06AF9 /* libPods-OneTimePasswordExampleTests.a */; }; /* End PBXBuildFile section */ @@ -57,9 +55,6 @@ 08C8E27D26BBA377006D4608 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 4F8B41242703520D00CF6A1A /* SettingController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SettingController.m; sourceTree = ""; }; 4F8B4126270484D900CF6A1A /* SettingController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SettingController.h; sourceTree = ""; }; - 4F8B41272705F8A900CF6A1A /* SettingsTableViewCell.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SettingsTableViewCell.h; sourceTree = ""; }; - 4F8B41282705F8CF00CF6A1A /* SettingsTableViewCell.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = SettingsTableViewCell.m; sourceTree = ""; }; - 4F8B412C2709A50E00CF6A1A /* SettingTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = SettingTableViewCell.xib; sourceTree = ""; }; 62EA47A9FA5474BBDDECC144 /* Pods-OneTimePasswordExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OneTimePasswordExample.debug.xcconfig"; path = "Target Support Files/Pods-OneTimePasswordExample/Pods-OneTimePasswordExample.debug.xcconfig"; sourceTree = ""; }; 736A6813388591A6692CC8C4 /* Pods-OneTimePasswordExampleTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OneTimePasswordExampleTests.release.xcconfig"; path = "Target Support Files/Pods-OneTimePasswordExampleTests/Pods-OneTimePasswordExampleTests.release.xcconfig"; sourceTree = ""; }; BC7DC5E5BD3FFB6BD8F06AF9 /* libPods-OneTimePasswordExampleTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-OneTimePasswordExampleTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -140,8 +135,6 @@ isa = PBXGroup; children = ( 089ECCC127417BDA00C7EAB8 /* Model */, - 4F8B41272705F8A900CF6A1A /* SettingsTableViewCell.h */, - 4F8B41282705F8CF00CF6A1A /* SettingsTableViewCell.m */, 08C8E26B26BBA376006D4608 /* AppDelegate.h */, 08C8E26C26BBA376006D4608 /* AppDelegate.m */, 08C8E26E26BBA376006D4608 /* SceneDelegate.h */, @@ -151,7 +144,6 @@ 4F8B41242703520D00CF6A1A /* SettingController.m */, 4F8B4126270484D900CF6A1A /* SettingController.h */, 08C8E27426BBA376006D4608 /* Main.storyboard */, - 4F8B412C2709A50E00CF6A1A /* SettingTableViewCell.xib */, 08C8E27726BBA377006D4608 /* Assets.xcassets */, 08C8E27926BBA377006D4608 /* LaunchScreen.storyboard */, 08C8E27C26BBA377006D4608 /* Info.plist */, @@ -270,7 +262,6 @@ files = ( 08C8E27B26BBA377006D4608 /* LaunchScreen.storyboard in Resources */, 08C8E27826BBA377006D4608 /* Assets.xcassets in Resources */, - 4F8B412D2709A50E00CF6A1A /* SettingTableViewCell.xib in Resources */, 08C8E27626BBA376006D4608 /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -341,7 +332,6 @@ 08C8E27326BBA376006D4608 /* ViewController.m in Sources */, 08804D92274BE72D00634C07 /* OneTimePasswordConverter.m in Sources */, 08C8E26D26BBA376006D4608 /* AppDelegate.m in Sources */, - 4F8B41292705F8CF00CF6A1A /* SettingsTableViewCell.m in Sources */, 4F8B41252703520D00CF6A1A /* SettingController.m in Sources */, 08C8E27E26BBA377006D4608 /* main.m in Sources */, 08C8E27026BBA376006D4608 /* SceneDelegate.m in Sources */, diff --git a/OneTimePasswordExample/SettingTableViewCell.storyboard b/OneTimePasswordExample/SettingTableViewCell.storyboard deleted file mode 100644 index dd79351..0000000 --- a/OneTimePasswordExample/SettingTableViewCell.storyboard +++ /dev/null @@ -1,30 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/OneTimePasswordExample/SettingTableViewCell.xib b/OneTimePasswordExample/SettingTableViewCell.xib deleted file mode 100644 index 631227f..0000000 --- a/OneTimePasswordExample/SettingTableViewCell.xib +++ /dev/null @@ -1,51 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/OneTimePasswordExample/SettingsTableViewCell.h b/OneTimePasswordExample/SettingsTableViewCell.h deleted file mode 100644 index 84946b0..0000000 --- a/OneTimePasswordExample/SettingsTableViewCell.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// SettingTableViewCell.h -// OneTimePasswordExample -// -// Created by MaiNakagami on 2021/09/30. -// - -#import - -NS_ASSUME_NONNULL_BEGIN - -@interface SettingsTableViewCell : UITableViewCell - -@property (weak, nonatomic) IBOutlet UILabel *titleLabel; -@property (weak, nonatomic) IBOutlet UILabel *valueLabel; - -@end - -NS_ASSUME_NONNULL_END diff --git a/OneTimePasswordExample/SettingsTableViewCell.m b/OneTimePasswordExample/SettingsTableViewCell.m deleted file mode 100644 index 40b44d4..0000000 --- a/OneTimePasswordExample/SettingsTableViewCell.m +++ /dev/null @@ -1,23 +0,0 @@ -// -// SettingTableViewCell.m -// OneTimePasswordExample -// -// Created by MaiNakagami on 2021/09/30. -// - -#import "SettingsTableViewCell.h" - -@implementation SettingsTableViewCell - -- (void)awakeFromNib { - [super awakeFromNib]; - // Initialization code -} - -- (void)setSelected:(BOOL)selected animated:(BOOL)animated { - [super setSelected:selected animated:animated]; - - // Configure the view for the selected state -} - -@end