Adds string form field cell for use in table views to edit a string property.

This commit is contained in:
2020-09-12 00:17:41 -07:00
parent e3384538a5
commit a8c88feb1f
6 changed files with 101 additions and 1 deletions

View File

@@ -8,10 +8,11 @@
#import <UIKit/UIKit.h>
#import "Monster.h"
#import "EditableShortStringTableViewCell.h"
NS_ASSUME_NONNULL_BEGIN
@interface EditMonsterViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@interface EditMonsterViewController : UIViewController <UITableViewDelegate, UITableViewDataSource, EditableShortStringDelegate>
@property Monster* originalMonster;
@property (weak, nonatomic) IBOutlet UITableView *monsterTableView;

View File

@@ -7,6 +7,7 @@
//
#import "EditMonsterViewController.h"
#import "EditableShortStringTableViewCell.h"
@interface EditMonsterViewController ()

View File

@@ -0,0 +1,20 @@
//
// EditableFormFieldDelegate.h
// MonsterCards
//
// Created by Tom Hicks on 9/9/20.
// Copyright © 2020 Tom Hicks. All rights reserved.
//
#ifndef EditableFormFieldDelegate_h
#define EditableFormFieldDelegate_h
@protocol EditableFormFieldDelegate <NSObject>
@optional
-(void)editableValueDidChange:(NSObject*)value forIdentifier:(NSString*)identifier andType:(NSString*)type;
@end
#endif /* EditableFormFieldDelegate_h */

View File

@@ -0,0 +1,30 @@
//
// EditableShortStringTableViewCell.h
// MonsterCards
//
// Created by Tom Hicks on 9/9/20.
// Copyright © 2020 Tom Hicks. All rights reserved.
//
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@protocol EditableShortStringDelegate <NSObject>
@optional
-(void)editableValueDidChange:(NSString*)value forIdentifier:(NSString*)identifier andType:(NSString*)type;
@end
@interface EditableShortStringTableViewCell : UITableViewCell <UITextFieldDelegate>
@property NSString* identifier;
@property NSString* label;
@property NSString* value;
@property (nonatomic, weak) id<EditableShortStringDelegate> delegate;
@property (weak, nonatomic) IBOutlet UITextField *textField;
@end
NS_ASSUME_NONNULL_END

View File

@@ -0,0 +1,32 @@
//
// EditableShortStringTableViewCell.m
// MonsterCards
//
// Created by Tom Hicks on 9/9/20.
// Copyright © 2020 Tom Hicks. All rights reserved.
//
#import "EditableShortStringTableViewCell.h"
@implementation EditableShortStringTableViewCell
- (void)awakeFromNib {
[super awakeFromNib];
// Initialization code
self.textField.delegate = self;
}
#pragma mark - UITextFieldDelegate
- (BOOL)textField:(UITextField *)textField
shouldChangeCharactersInRange:(NSRange)range
replacementString:(NSString *)string {
// TODO: See this link for a potentially better way to get this text https://stackoverflow.com/questions/19110617/uitextfieldtextdidchangenotification-ios7-not-fired
NSString *finalString = [textField.text stringByReplacingCharactersInRange:range withString:string];
if (self.delegate != nil) {
[self.delegate editableValueDidChange:finalString forIdentifier:self.identifier andType:@"String"];
}
return YES;
}
@end