RAEditMultInputCell.m 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. //
  2. // RAEditMultInputCell.m
  3. // Apex And Drivers
  4. //
  5. // Created by Jack on 2018/6/4.
  6. // Copyright © 2018年 USAI. All rights reserved.
  7. //
  8. #import "RAEditMultInputCell.h"
  9. #import "RAEditMultInputModel.h"
  10. @interface RAEditMultInputCell () <UITextViewDelegate,RAEditModelDelegate>
  11. @property (strong, nonatomic) IBOutlet UILabel *titleLabel;
  12. @property (nonatomic,strong) IBOutlet UILabel *startLabel;
  13. @property (strong, nonatomic) IBOutlet UITextView *inputView;
  14. @end
  15. @implementation RAEditMultInputCell
  16. - (void)awakeFromNib {
  17. [super awakeFromNib];
  18. // Initialization code
  19. self.model = nil;
  20. self.inputView.layer.borderWidth = 0.5f;
  21. self.inputView.layer.borderColor = [UIColor lightGrayColor].CGColor;
  22. }
  23. - (void)prepareForReuse {
  24. [super prepareForReuse];
  25. self.model = nil;
  26. self.delegate = nil;
  27. }
  28. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  29. [super setSelected:selected animated:animated];
  30. // Configure the view for the selected state
  31. }
  32. - (void)setModel:(RAEditMultInputModel *)model {
  33. if (_model) {
  34. _model.delegate = nil;
  35. }
  36. _model = model;
  37. _model.delegate = self;
  38. [self refresh];
  39. }
  40. #pragma mark - Model Delegate
  41. - (void)refresh {
  42. self.titleLabel.text = _model.title;
  43. self.inputView.text = _model.value;
  44. self.startLabel.hidden = !_model.required;
  45. }
  46. - (void)unbind {
  47. _model = nil;
  48. [self refresh];
  49. }
  50. #pragma mark - TextView Delegate
  51. - (BOOL)textViewShouldBeginEditing:(UITextView *)textView {
  52. if (self.delegate && [self.delegate respondsToSelector:@selector(beginEditMultInputCell:)]) {
  53. [self.delegate beginEditMultInputCell:self];
  54. }
  55. return YES;
  56. }
  57. - (BOOL)textViewShouldEndEditing:(UITextView *)textView {
  58. if (self.delegate && [self.delegate respondsToSelector:@selector(endEditMultInputCell:)]) {
  59. [self.delegate endEditMultInputCell:self];
  60. }
  61. return YES;
  62. }
  63. - (void)textViewDidChange:(UITextView *)textView {
  64. [self.model updateValue:textView.text];
  65. }
  66. @end