Adds select field with picker as TextField inputView.
This commit is contained in:
@@ -394,6 +394,45 @@
|
||||
<outlet property="switchView" destination="L1a-6J-Yco" id="tTF-vZ-9gZ"/>
|
||||
</connections>
|
||||
</tableViewCell>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="MCSelectField" id="PQF-mC-UlI" userLabel="MCSelectField" customClass="MCSelectFieldTableViewCell">
|
||||
<rect key="frame" x="0.0" y="158.5" width="414" height="37.5"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="PQF-mC-UlI" id="Wcu-Sa-z2O">
|
||||
<rect key="frame" x="0.0" y="0.0" width="414" height="37.5"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="lik-sI-94j" userLabel="Label View">
|
||||
<rect key="frame" x="20" y="8" width="42" height="21.5"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="21" id="A1K-Wk-Nuf"/>
|
||||
</constraints>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<textField opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" borderStyle="roundedRect" textAlignment="natural" minimumFontSize="17" translatesAutoresizingMaskIntoConstraints="NO" id="DFa-Hd-laX" userLabel="Text Field">
|
||||
<rect key="frame" x="82" y="2" width="312" height="34"/>
|
||||
<constraints>
|
||||
<constraint firstAttribute="height" constant="34" id="zHt-9x-mSt"/>
|
||||
</constraints>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="14"/>
|
||||
<textInputTraits key="textInputTraits"/>
|
||||
</textField>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="DFa-Hd-laX" firstAttribute="centerY" secondItem="Wcu-Sa-z2O" secondAttribute="centerY" id="CAr-SD-zJQ"/>
|
||||
<constraint firstItem="lik-sI-94j" firstAttribute="centerY" secondItem="Wcu-Sa-z2O" secondAttribute="centerY" id="NXK-tA-2fO"/>
|
||||
<constraint firstItem="lik-sI-94j" firstAttribute="leading" secondItem="Wcu-Sa-z2O" secondAttribute="leading" constant="20" id="fea-zT-1Gp"/>
|
||||
<constraint firstAttribute="trailing" secondItem="DFa-Hd-laX" secondAttribute="trailing" constant="20" id="k98-fH-Q1Z"/>
|
||||
<constraint firstItem="DFa-Hd-laX" firstAttribute="leading" secondItem="lik-sI-94j" secondAttribute="trailing" constant="20" id="pF8-P8-BrC"/>
|
||||
<constraint firstItem="lik-sI-94j" firstAttribute="top" secondItem="Wcu-Sa-z2O" secondAttribute="top" constant="8" id="tXM-6N-Dk1"/>
|
||||
</constraints>
|
||||
</tableViewCellContentView>
|
||||
<connections>
|
||||
<outlet property="labelView" destination="lik-sI-94j" id="TYU-vE-Agy"/>
|
||||
<outlet property="textField" destination="DFa-Hd-laX" id="8fm-vK-dar"/>
|
||||
</connections>
|
||||
</tableViewCell>
|
||||
</prototypes>
|
||||
</tableView>
|
||||
</subviews>
|
||||
|
||||
@@ -15,7 +15,8 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@property NSString* name;
|
||||
@property BOOL speaks;
|
||||
|
||||
-(id)initWithName: (NSString*)name andSpeaks: (BOOL)canSpeak;
|
||||
-(id)initWithName:(NSString*)name
|
||||
andSpeaks:(BOOL)canSpeak;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@
|
||||
return self;
|
||||
}
|
||||
|
||||
-(id)initWithName: (NSString*)name andSpeaks: (BOOL)canSpeak {
|
||||
-(id)initWithName:(NSString*)name
|
||||
andSpeaks:(BOOL)canSpeak {
|
||||
self = [super init];
|
||||
|
||||
self.name = name;
|
||||
|
||||
@@ -504,6 +504,10 @@ NSString* const kMonsterSizeGargantuan = @"gargantuan";
|
||||
self.swimSpeed = monster.swimSpeed;
|
||||
self.hasCustomSpeed = monster.hasCustomSpeed;
|
||||
self.customSpeed = monster.customSpeed;
|
||||
self.armorType = monster.armorType;
|
||||
self.naturalArmorBonus = monster.naturalArmorBonus;
|
||||
self.hasShield = monster.hasShield;
|
||||
self.customArmor = monster.customArmor;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -7,9 +7,10 @@
|
||||
//
|
||||
|
||||
#import "EditMonsterViewController.h"
|
||||
#import "MCShortStringFieldTableViewCell.h"
|
||||
#import "MCIntegerFieldTableViewCell.h"
|
||||
#import "MCBooleanFieldTableViewCell.h"
|
||||
#import "MCIntegerFieldTableViewCell.h"
|
||||
#import "MCSelectFieldTableViewCell.h"
|
||||
#import "MCShortStringFieldTableViewCell.h"
|
||||
#import "AppDelegate.h"
|
||||
|
||||
@interface EditMonsterViewController ()
|
||||
@@ -55,12 +56,48 @@ const int kAbilityScoreSectionRowIndexCharisma = 5;
|
||||
|
||||
@implementation EditMonsterViewController {
|
||||
NSManagedObjectContext *_context;
|
||||
NSArray<MCChoice*>* _armorTypes;
|
||||
}
|
||||
|
||||
- (void)viewDidLoad {
|
||||
[super viewDidLoad];
|
||||
AppDelegate *appDelegate = (AppDelegate*)UIApplication.sharedApplication.delegate;
|
||||
_context = appDelegate.persistentContainer.viewContext;
|
||||
|
||||
_armorTypes = [NSArray arrayWithObjects:
|
||||
[MCChoice choiceWithLabel:NSLocalizedString(@"None", @"")
|
||||
andValue:kArmorNameNone],
|
||||
[MCChoice choiceWithLabel:NSLocalizedString(@"Natural Armor", @"")
|
||||
andValue:kArmorNameNaturalArmor],
|
||||
[MCChoice choiceWithLabel:NSLocalizedString(@"Mage Armor", @"")
|
||||
andValue:kArmorNameMageArmor],
|
||||
[MCChoice choiceWithLabel:NSLocalizedString(@"Padded", @"")
|
||||
andValue:kArmorNamePadded],
|
||||
[MCChoice choiceWithLabel:NSLocalizedString(@"Leather", @"")
|
||||
andValue:kArmorNameLeather],
|
||||
[MCChoice choiceWithLabel:NSLocalizedString(@"Studded", @"")
|
||||
andValue:kArmorNameStuddedLeather],
|
||||
[MCChoice choiceWithLabel:NSLocalizedString(@"Hide", @"")
|
||||
andValue:kArmorNameHide],
|
||||
[MCChoice choiceWithLabel:NSLocalizedString(@"Chain Shirt", @"")
|
||||
andValue:kArmorNameChainShirt],
|
||||
[MCChoice choiceWithLabel:NSLocalizedString(@"Scale Mail", @"")
|
||||
andValue:kArmorNameScaleMail],
|
||||
[MCChoice choiceWithLabel:NSLocalizedString(@"Breastplate", @"")
|
||||
andValue:kArmorNameBreastplate],
|
||||
[MCChoice choiceWithLabel:NSLocalizedString(@"Half Plate", @"")
|
||||
andValue:kArmorNameHalfPlate],
|
||||
[MCChoice choiceWithLabel:NSLocalizedString(@"Ring Mail", @"")
|
||||
andValue:kArmorNameRingMail],
|
||||
[MCChoice choiceWithLabel:NSLocalizedString(@"Chain Mail", @"")
|
||||
andValue:kArmorNameChainMail],
|
||||
[MCChoice choiceWithLabel:NSLocalizedString(@"Splint", @"")
|
||||
andValue:kArmorNameSplintMail],
|
||||
[MCChoice choiceWithLabel:NSLocalizedString(@"Plate", @"")
|
||||
andValue:kArmorNamePlateMail],
|
||||
[MCChoice choiceWithLabel:NSLocalizedString(@"Other", @"")
|
||||
andValue:kArmorNameOther],
|
||||
nil];
|
||||
|
||||
self.monsterTableView.dataSource = self;
|
||||
self.monsterTableView.delegate = self;
|
||||
@@ -131,6 +168,24 @@ const int kAbilityScoreSectionRowIndexCharisma = 5;
|
||||
return cell;
|
||||
}
|
||||
|
||||
- (MCSelectFieldTableViewCell*) makeSelectCellFromTableView:(UITableView*)tableView
|
||||
withIdentifier:(NSString*)identifier
|
||||
label:(NSString*)label
|
||||
initialValue:(NSObject*)initialValue
|
||||
andChoices:(NSArray*)choices {
|
||||
MCSelectFieldTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MCSelectField"];
|
||||
if (!cell || ![cell isKindOfClass:[MCSelectFieldTableViewCell class]]) {
|
||||
return nil;
|
||||
}
|
||||
cell.delegate = self;
|
||||
cell.identifier = identifier;
|
||||
cell.label = label;
|
||||
cell.selectedValue = initialValue;
|
||||
cell.choices = choices;
|
||||
|
||||
return cell;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Navigation
|
||||
|
||||
@@ -160,7 +215,7 @@ const int kAbilityScoreSectionRowIndexCharisma = 5;
|
||||
// * Alignment
|
||||
return 8;
|
||||
case kSectionIndexArmor:
|
||||
return 0;
|
||||
return 4;
|
||||
case kSectionIndexSpeed:
|
||||
return 8;
|
||||
case kSectionIndexAbilityScores:
|
||||
@@ -181,7 +236,7 @@ titleForHeaderInSection:(NSInteger)section {
|
||||
case kSectionIndexBasicInfo:
|
||||
return NSLocalizedString(@"Basic Info", @"Section title");
|
||||
case kSectionIndexArmor:
|
||||
return NSLocalizedString(@"Armor and HP", @"Section title");
|
||||
return NSLocalizedString(@"Armor", @"Section title");
|
||||
case kSectionIndexSpeed:
|
||||
return NSLocalizedString(@"Speed", @"Section title");
|
||||
case kSectionIndexAbilityScores:
|
||||
@@ -250,6 +305,31 @@ titleForHeaderInSection:(NSInteger)section {
|
||||
break;
|
||||
case kSectionIndexArmor:
|
||||
switch (indexPath.row) {
|
||||
case kArmorSectionRowIndexArmorType:
|
||||
newCell = [self makeSelectCellFromTableView:self.monsterTableView
|
||||
withIdentifier:@"monster.armorType"
|
||||
label:NSLocalizedString(@"Type", @"")
|
||||
initialValue:self.editingMonster.armorType
|
||||
andChoices:_armorTypes];
|
||||
break;
|
||||
case kArmorSectionRowIndexHasShield:
|
||||
newCell = [self makeBooleanCellFromTableView:self.monsterTableView
|
||||
withIdentifier:@"monster.hasShield"
|
||||
label:NSLocalizedString(@"Shield", @"")
|
||||
andInitialValue:self.editingMonster.hasShield];
|
||||
break;
|
||||
case kArmorSectionRowIndexCustomArmor:
|
||||
newCell = [self makeShortStringCellFromTableView:self.monsterTableView
|
||||
withIdentifier:@"monster.customArmor"
|
||||
label:NSLocalizedString(@"Custom Armor", @"")
|
||||
andInitialValue:self.editingMonster.customArmor];
|
||||
break;
|
||||
case kArmorSectionRowIndexNaturalArmorBonus:
|
||||
newCell = [self makeIntegerCellFromTableView:self.monsterTableView
|
||||
withIdentifier:@"monster.naturalArmorBonus"
|
||||
label:NSLocalizedString(@"Natural Armor Bonus", @"")
|
||||
andInitialValue:self.editingMonster.naturalArmorBonus];
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case kSectionIndexSpeed:
|
||||
@@ -373,6 +453,8 @@ titleForHeaderInSection:(NSInteger)section {
|
||||
self.editingMonster.hpText = (NSString*)value;
|
||||
} else if ([@"monster.customSpeed" isEqualToString:identifier]) {
|
||||
self.editingMonster.customSpeed = (NSString*)value;
|
||||
} else if ([@"monster.customArmor" isEqualToString:identifier]) {
|
||||
self.editingMonster.customArmor = (NSString*)value;
|
||||
}
|
||||
}
|
||||
if ([kMCFieldValueTypeInteger isEqualToString:type]) {
|
||||
@@ -400,6 +482,8 @@ titleForHeaderInSection:(NSInteger)section {
|
||||
self.editingMonster.flySpeed = [(NSNumber*)value intValue];
|
||||
} else if ([@"monster.swimSpeed" isEqualToString:identifier]) {
|
||||
self.editingMonster.swimSpeed = [(NSNumber*)value intValue];
|
||||
} else if ([@"monster.naturalArmorBonus" isEqualToString:identifier]) {
|
||||
self.editingMonster.naturalArmorBonus = [(NSNumber*)value intValue];
|
||||
}
|
||||
}
|
||||
if ([kMCFieldValueTypeBoolean isEqualToString:type]) {
|
||||
@@ -409,6 +493,13 @@ titleForHeaderInSection:(NSInteger)section {
|
||||
self.editingMonster.canHover = [(NSNumber*)value boolValue];
|
||||
} else if ([@"monster.hasCustomSpeed" isEqualToString:identifier]) {
|
||||
self.editingMonster.hasCustomSpeed = [(NSNumber*)value boolValue];
|
||||
} else if ([@"monster.hasShield" isEqualToString:identifier]) {
|
||||
self.editingMonster.hasShield = [(NSNumber*)value boolValue];
|
||||
}
|
||||
}
|
||||
if ([kMCFieldValueTypeChoice isEqualToString:type]) {
|
||||
if ([@"monster.armorType" isEqualToString:identifier]) {
|
||||
self.editingMonster.armorType = (NSString*)value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
28
iOS/MonsterCards/Views/FormFields/MCChoice.h
Normal file
28
iOS/MonsterCards/Views/FormFields/MCChoice.h
Normal file
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// MCChoice.h
|
||||
// MonsterCards
|
||||
//
|
||||
// Created by Tom Hicks on 9/26/20.
|
||||
// Copyright © 2020 Tom Hicks. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface MCChoice : NSObject
|
||||
|
||||
@property NSString* label;
|
||||
@property NSObject* value;
|
||||
|
||||
+(id)choiceWithLabel:(NSString*)label
|
||||
andValue:(NSObject*)value;
|
||||
|
||||
-(id)initWithLabel:(NSString*)label
|
||||
andValue:(NSObject*)value;
|
||||
|
||||
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
29
iOS/MonsterCards/Views/FormFields/MCChoice.m
Normal file
29
iOS/MonsterCards/Views/FormFields/MCChoice.m
Normal file
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// MCChoice.m
|
||||
// MonsterCards
|
||||
//
|
||||
// Created by Tom Hicks on 9/26/20.
|
||||
// Copyright © 2020 Tom Hicks. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MCChoice.h"
|
||||
|
||||
@implementation MCChoice
|
||||
|
||||
+(id)choiceWithLabel:(NSString*)label
|
||||
andValue:(NSObject*)value {
|
||||
return [[MCChoice alloc] initWithLabel:label
|
||||
andValue:value];
|
||||
}
|
||||
|
||||
-(id)initWithLabel:(NSString*)label
|
||||
andValue:(NSObject*)value {
|
||||
self = [super init];
|
||||
|
||||
self.label = label;
|
||||
self.value = value;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -12,5 +12,6 @@
|
||||
extern NSString* const kMCFieldValueTypeInteger;
|
||||
extern NSString* const kMCFieldValueTypeString;
|
||||
extern NSString* const kMCFieldValueTypeBoolean;
|
||||
extern NSString* const kMCFieldValueTypeChoice;
|
||||
|
||||
#endif /* MCFormFieldConstants_h */
|
||||
|
||||
@@ -12,3 +12,4 @@
|
||||
NSString* const kMCFieldValueTypeInteger = @"Integer";
|
||||
NSString* const kMCFieldValueTypeString = @"String";
|
||||
NSString* const kMCFieldValueTypeBoolean = @"Boolean";
|
||||
NSString* const kMCFieldValueTypeChoice = @"Choice";
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// MCSelectFieldTableViewCell.h
|
||||
// MonsterCards
|
||||
//
|
||||
// Created by Tom Hicks on 9/26/20.
|
||||
// Copyright © 2020 Tom Hicks. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "MCFormFieldDelegate.h"
|
||||
#import "MCChoice.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface MCSelectFieldTableViewCell : UITableViewCell<UIPickerViewDataSource, UIPickerViewDelegate, UITextFieldDelegate>
|
||||
|
||||
@property NSString* identifier;
|
||||
@property NSString* label;
|
||||
@property NSObject* selectedValue;
|
||||
@property NSArray<MCChoice*>* choices;
|
||||
|
||||
@property (weak, nonatomic) id<MCFormFieldDelegate> delegate;
|
||||
@property (weak, nonatomic) IBOutlet UITextField *textField;
|
||||
@property (weak, nonatomic) IBOutlet UILabel *labelView;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
||||
157
iOS/MonsterCards/Views/FormFields/MCSelectFieldTableViewCell.m
Normal file
157
iOS/MonsterCards/Views/FormFields/MCSelectFieldTableViewCell.m
Normal file
@@ -0,0 +1,157 @@
|
||||
//
|
||||
// MCSelectFieldTableViewCell.m
|
||||
// MonsterCards
|
||||
//
|
||||
// Created by Tom Hicks on 9/26/20.
|
||||
// Copyright © 2020 Tom Hicks. All rights reserved.
|
||||
//
|
||||
|
||||
#import "MCSelectFieldTableViewCell.h"
|
||||
|
||||
@implementation MCSelectFieldTableViewCell {
|
||||
MCChoice* _selectedChoice;
|
||||
}
|
||||
|
||||
@synthesize choices = _choices;
|
||||
-(void)setChoices:(NSArray<MCChoice*>*)choices {
|
||||
// TODO: only do this if choices is different
|
||||
// TODO: update selectedValue and selectedIndex
|
||||
_choices = choices;
|
||||
|
||||
if (![_choices isEqualToArray:choices]) {
|
||||
self.selectedValue = _selectedValue;
|
||||
} else if (choices) {
|
||||
self.selectedValue = [choices firstObject].value;
|
||||
}
|
||||
}
|
||||
-(NSArray<MCChoice*>*)choices {
|
||||
return _choices;
|
||||
}
|
||||
|
||||
@synthesize identifier = _identifier;
|
||||
-(void)setIdentifier:(NSString*)identifier {
|
||||
if (![_identifier isEqualToString:identifier]) {
|
||||
_identifier = identifier;
|
||||
}
|
||||
}
|
||||
-(NSString*)identifier {
|
||||
return _identifier;
|
||||
}
|
||||
|
||||
@synthesize label = _label;
|
||||
-(void)setLabel:(NSString*)label {
|
||||
if (![_label isEqualToString:label]) {
|
||||
_label = label;
|
||||
}
|
||||
if (_labelView && ![_labelView.text isEqualToString:label]) {
|
||||
_labelView.text = label;
|
||||
}
|
||||
}
|
||||
-(NSString*)label {
|
||||
return _label;
|
||||
}
|
||||
|
||||
-(MCChoice*)findChoiceWithValue:(NSObject*)value
|
||||
inArray:(NSArray*)array {
|
||||
NSPredicate *predicate = [NSPredicate predicateWithBlock:^BOOL(id element, NSDictionary *bindings) {
|
||||
if (![element isKindOfClass:[MCChoice class]]) {
|
||||
return NO;
|
||||
}
|
||||
MCChoice *choice = (MCChoice*)element;
|
||||
return [choice.value isEqual:value];
|
||||
}];
|
||||
NSArray<MCChoice*> *matchingChoices = [_choices filteredArrayUsingPredicate:predicate];
|
||||
MCChoice *foundChoice = matchingChoices.count > 0 ? matchingChoices.firstObject : nil;
|
||||
return foundChoice;
|
||||
}
|
||||
|
||||
@synthesize selectedValue = _selectedValue;
|
||||
-(void)setSelectedValue:(NSObject*)value {
|
||||
if (!_choices) {
|
||||
// choices hasn't been initialized yet so just set our selected value until choices is set
|
||||
_selectedValue = value;
|
||||
}
|
||||
MCChoice *foundChoice = [self findChoiceWithValue:value
|
||||
inArray:_choices];
|
||||
if (![_selectedChoice isEqual:foundChoice] || ![_selectedValue isEqual:foundChoice.value]) {
|
||||
_selectedChoice = foundChoice;
|
||||
_selectedValue = foundChoice.value;
|
||||
if (_delegate) {
|
||||
[_delegate editableValueDidChange:_selectedValue
|
||||
forIdentifier:_identifier
|
||||
andType:kMCFieldValueTypeChoice];
|
||||
}
|
||||
}
|
||||
self.textField.text = _selectedChoice != nil
|
||||
? _selectedChoice.label != nil
|
||||
? _selectedChoice.label
|
||||
: @""
|
||||
: @"";
|
||||
}
|
||||
-(NSObject*)selectedValue {
|
||||
return _selectedValue;
|
||||
}
|
||||
|
||||
- (void)awakeFromNib {
|
||||
[super awakeFromNib];
|
||||
UIPickerView *childPicker = [[UIPickerView alloc] init];
|
||||
childPicker.delegate = self;
|
||||
childPicker.dataSource = self;
|
||||
self.textField.inputView = childPicker;
|
||||
|
||||
UIToolbar *toolbar = [[UIToolbar alloc] init];
|
||||
[toolbar sizeToFit];
|
||||
|
||||
UIBarButtonItem *button =
|
||||
[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Done", @"Button label")
|
||||
style:UIBarButtonItemStylePlain
|
||||
target:self
|
||||
action:@selector(choiceSelected)];
|
||||
[toolbar setItems:@[button]
|
||||
animated:true];
|
||||
[toolbar setUserInteractionEnabled:YES];
|
||||
self.textField.inputAccessoryView = toolbar;
|
||||
self.textField.hidden = NO;
|
||||
self.textField.text = _selectedChoice.label;
|
||||
self.textField.delegate = self;
|
||||
}
|
||||
|
||||
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
|
||||
[super setSelected:selected animated:animated];
|
||||
|
||||
// Configure the view for the selected state
|
||||
}
|
||||
|
||||
- (void)choiceSelected {
|
||||
[self endEditing:true];
|
||||
}
|
||||
|
||||
#pragma mark - UIPickerViewDataSource
|
||||
|
||||
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
|
||||
return 1;
|
||||
}
|
||||
|
||||
- (NSInteger)pickerView:(UIPickerView *)pickerView
|
||||
numberOfRowsInComponent:(NSInteger)component {
|
||||
return [_choices count];
|
||||
}
|
||||
|
||||
#pragma mark - UIPickerViewDelegate
|
||||
|
||||
- (NSString *)pickerView:(UIPickerView *)pickerView
|
||||
titleForRow:(NSInteger)row
|
||||
forComponent:(NSInteger)component {
|
||||
return [_choices objectAtIndex:row].label;
|
||||
}
|
||||
|
||||
- (void)pickerView:(UIPickerView *)pickerView
|
||||
didSelectRow:(NSInteger)row
|
||||
inComponent:(NSInteger)component {
|
||||
|
||||
_selectedChoice = [_choices objectAtIndex:row];
|
||||
self.textField.text = _selectedChoice.label;
|
||||
self.selectedValue = _selectedChoice.value;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user