XLFormBaseCell.m 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // XLFormBaseCell.m
  3. // XLForm ( https://github.com/xmartlabs/XLForm )
  4. //
  5. // Copyright (c) 2015 Xmartlabs ( http://xmartlabs.com )
  6. //
  7. //
  8. // Permission is hereby granted, free of charge, to any person obtaining a copy
  9. // of this software and associated documentation files (the "Software"), to deal
  10. // in the Software without restriction, including without limitation the rights
  11. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. // copies of the Software, and to permit persons to whom the Software is
  13. // furnished to do so, subject to the following conditions:
  14. //
  15. // The above copyright notice and this permission notice shall be included in
  16. // all copies or substantial portions of the Software.
  17. //
  18. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. // THE SOFTWARE.
  25. #import "XLFormBaseCell.h"
  26. @implementation XLFormBaseCell
  27. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  28. {
  29. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  30. if (self) {
  31. [self configure];
  32. }
  33. return self;
  34. }
  35. - (void)awakeFromNib
  36. {
  37. [super awakeFromNib];
  38. [self configure];
  39. }
  40. - (void)configure
  41. {
  42. }
  43. - (void)update
  44. {
  45. self.textLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
  46. self.detailTextLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
  47. self.textLabel.textColor = self.rowDescriptor.isDisabled ? [UIColor grayColor] : [UIColor blackColor];
  48. }
  49. -(void)highlight
  50. {
  51. }
  52. -(void)unhighlight
  53. {
  54. }
  55. -(XLFormViewController *)formViewController
  56. {
  57. id responder = self;
  58. while (responder){
  59. if ([responder isKindOfClass:[XLFormViewController class]]){
  60. return responder;
  61. }
  62. responder = [responder nextResponder];
  63. }
  64. return nil;
  65. }
  66. #pragma mark - Navigation Between Fields
  67. -(UIView *)inputAccessoryView
  68. {
  69. UIView * inputAccessoryView = [self.formViewController inputAccessoryViewForRowDescriptor:self.rowDescriptor];
  70. if (inputAccessoryView){
  71. return inputAccessoryView;
  72. }
  73. return [super inputAccessoryView];
  74. }
  75. -(BOOL)formDescriptorCellCanBecomeFirstResponder
  76. {
  77. return NO;
  78. }
  79. #pragma mark -
  80. -(BOOL)becomeFirstResponder
  81. {
  82. BOOL result = [super becomeFirstResponder];
  83. if (result){
  84. [self.formViewController beginEditing:self.rowDescriptor];
  85. }
  86. return result;
  87. }
  88. -(BOOL)resignFirstResponder
  89. {
  90. BOOL result = [super resignFirstResponder];
  91. if (result){
  92. [self.formViewController endEditing:self.rowDescriptor];
  93. }
  94. return result;
  95. }
  96. @end